Boost logo

Boost :

Subject: Re: [boost] [thread] semaphore
From: Jonathan Wakely (jwakely.boost_at_[hidden])
Date: 2013-09-18 06:15:37


On 18 September 2013 07:19, Tim Blechmann wrote:
>> As I understood the reason semaphores were not included in c++11 was
>> because they were too hard to use and the recommendation is to just use
>> condition_variable instead.
>
> i'm not sure about the rationale for not including semaphores, but tbo
> condition_variables are not exactly easy to use, either and i've seen a
> lot of code, which does not use them correctly. also the API is a bit
> crippled, as they do not allow to identify spurious wakeups ...

Why do you care if a wakeup is spurious? A condition_variable should
be associated with some condition (the clue is in the name) and so
when you wake up you re-check the condition.

If the condition is true then you don't need to care whether you woke
up because notified or you woke up spuriously but the condition
happened to be true anyway (e.g. the condition was made true by
another thread but you woke up just before it notified you.)

If you're not checking some predicate then you're using it wrong.


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