- 论坛徽章:
- 0
|
本帖最后由 weichuang02 于 2013-06-05 11:25 编辑
man phread_cond出来的内容是这样的:
DESCRIPTION
A condition (short for ``condition variable'') is a synchronization device that allows threads to suspend execution and
relinquish the processors until some predicate on shared data is satisfied. The basic operations on conditions are: signal
the condition (when the predicate becomes true), and wait for the condition, suspending the thread execution until another
thread signals the condition.
A condition variable must always be associated with a mutex, to avoid the race condition where a thread prepares to wait on
a condition variable and another thread signals the condition just before the first thread actually waits on it.
想不通的一点是,既然已经有了pthread_mutex_lock这样的线程锁,那么pthread_cond看起来有点像windodws平台的Event概念,就是一个事件通知的句柄。
但是windows平台的mutex和event是相互独立的,并没有规定event要和mutex一起用。那么为什么pthread要规定 A condition variable must always be associated with a mutex呢?
谢谢指点! |
|