我对线程有点新,所以你不得不原谅这个问题的天真。pthread_join是如何实现的?
pthread_join
是如何实现的?它是如何影响线程调度的?
我总是使用while循环实现图片pthread_join
,只是导致调用线程退出,直到目标线程完成。像这样(非常近似的伪代码):
atomic bool done; thread_run { do_stuff(); done = true; } thread_join { while(!done) { thread_yield(); // basically, make the thread that calls "join" on // our thread yield until our thread completes } }
这是一个准确的描述,还是我大大简化了过程?
干杯!
他的代码和真实代码之间唯一真正的巨大差异是如果有备用核心,他的代码会导致加入的线程烧掉100%的CPU。 – 2011-08-30 13:10:38