小编cuc*_*koo的帖子

等待pthread_join()时是否需要pthread_yield()?

下面的代码中,是否需要pthread_yield()在主线程阻塞等待时调用pthread_join()

void *myThread(void *result)
{
   //do something here
   return 0;
}

int main()
{
   pthread_t tid;
   void *status = 0;
   int result;

   pthread_create(&tid, NULL, myThread, &result);
   
   // do I need pthread_yield() here?
   
   pthread_join(tid, &status);

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果不是,什么是有效的用例pthread_yield()?我能想到的大多数基本情况,操作系统/调度程序已经自动处理了。

c linux multithreading

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

标签 统计

c ×1

linux ×1

multithreading ×1