
6 Dec
2006
6 Dec
'06
9:30 p.m.
Yuval Ronen wrote:
Hello.
The Boost CV class forces that a mutex would be locked when calling wait(), but not when calling notify(). This seems a bit strange to me.
It isn't strange since notify is typically not called with the mutex locked. This would cause the awakened thread to immediately be put back to sleep to wait for the mutex.
As far as my understanding of CVs goes (and experience with them), locking when notifying is just as "makes sense" as locking when waiting. When waiting, we check the predicate, and when notifying, we change that predicate. And it is only obvious that all reads and writes to the shared-among-threads predicate should be locked. Shouldn't it?
It should.