我在 c 中创建了两个线程。我想由每个线程执行两个单独的函数。如何使一个特定的线程首先被执行。
#include <stdio.h>
#include <pthread.h>
void* function_1(void* p)
{
// statements
}
void* function_2(void* p)
{
// statements
}
int main(void)
{
pthread_t id1;
pthread_t id2;
pthread_create(&id1, NULL, function_1, NULL);
pthread_create(&id2, NULL, function_2, NULL);
pthread_exit(NULL);
}
Run Code Online (Sandbox Code Playgroud)
程序启动时如何使function_1在function_2之前执行?