Boost logo

Boost :

Subject: Re: [boost] [thread] semaphore
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-09-19 14:49:29


On Thu, Sep 19, 2013 at 9:24 PM, Niall Douglas <s_sourceforge_at_[hidden]>wrote:

> On 19 Sep 2013 at 20:27, Andrey Semashev wrote:
>
> > > Semaphores are ripe for people misusing them.
> >
> > ...and blessing for those who manage to use them right. The same could
> be said
> > about pretty much any component.
>
> Of course, but I see more frequent race conditions in semaphore using
> code than other systems. For example, ASIO has a race condition on
> IOCP writes if you allow its completion port semaphore to be higher
> than one.
>
> Semaphores are the best tool for a limited set of use cases, but I'd
> use them as a last resort.
>

Right, semaphores are a tool with its use cases. It should be used
carefully, but just as well as all threading primitives. Believe it or not,
I spend much more time debugging incorrect use of mutexes and CVs than
semaphores.

> If by contention you mean the semaphore has a permit count of 20 and
> the average threads in flow is 25, then that's not what I mean by
> contention.
>

No, it's more like a few hundred of threads in different processes
synchronizing on a single lock-free queue.


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