Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-12-06 16:30:15


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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk