|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-12-06 17:38:43
Yuval Ronen wrote:
> Peter Dimov wrote:
>> 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.
>
> Yes, but what's the harm in that? The notify simply change the state
> of the thread from "waiting on a CV" to "waiting on a mutex". I'm no
> operating system expert, but I guess it can be done with a flip of a
> flag (or two) inside the kernel. After that we continue normally.
It can be done in principle, but then you still need to make another kernel
call in unlock to wake up the thread that you already tried to wake up in
notify. If the unlock is done before the notify, it can take the fast path
and not enter the kernel (unless there's someone else waiting on the mutex).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk