pthread_cond_signal() release exactly one thread?

ⅰ亾dé卋堺 提交于 2019-12-22 13:01:24

问题


Does pthread_cond_signal unblock exactly one thread? If not, what will be the case it releases more than one thread? The specification says as follows:

The pthread_cond_signal() function shall unblock at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond).


回答1:


The pthreads specification allows for "spurious wakeups" in an implementation. See, for example, the hypothetical implementation of pthread_cond_signal and pthread_cond_wait sketched in the specification that allows for just this condition.

The possibility of spurious wakeups is why one always associates some predicate with a condition, and checks that predicate upon wakeup.



来源:https://stackoverflow.com/questions/18391146/pthread-cond-signal-release-exactly-one-thread

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!