小编Vin*_*nie的帖子

c - 如何强制使一个线程在c中首先执行

我在 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之前执行?

c linux multithreading pthreads

0
推荐指数
1
解决办法
53
查看次数

标签 统计

c ×1

linux ×1

multithreading ×1

pthreads ×1