r****o 发帖数: 1950 | 1 【 以下文字转载自 InterviewHackers 俱乐部 】
发信人: roufoo (五经勤向窗前读), 信区: InterviewHackers
标 题: 请问pthread_join()和pthread_yield()的区别。
发信站: BBS 未名空间站 (Mon Jun 7 18:33:04 2010, 美东)
看了这两个函数的说明,好像功能差不多啊,都是主线程要suspend,让一个新的线程
先运行。
那这两个函数具体有什么区别呢? | a*********9 发帖数: 523 | 2 记得pthread_yield是让OS自动调度, pthread_join是自己指明要等待的线程 | z*****9 发帖数: 86 | 3 Big difference.
yield just relinquishes CPU, calling it tells OS that there is no job to do
in the calling thread so OS should switch another thread in. Note that yield
is only a hint. The OS needs not to do anything useful in yield and it is
non-portable and dangerous to depending on the behavior of yield. sleep or
pause should be used instead if you do want to stop your thread.
join provides a way for you to make sure another thread is terminated and
get the termination status of the thread. T |
|