Boost logo

Boost :

Subject: Re: [boost] [Interprocess::Semaphore] Deadlock on more producers - one consumer problem
From: igaztanaga_at_[hidden]
Date: 2009-06-18 10:46:31


James Mansion wrote:
> Ion Gaztañaga wrote:
>> A semaphore post only increases a waiting thread if count was 0.
>> That's the behaviour of a semaphore.
> Not of Dijkstra's design it isn't. Conceptually a waiting consumer is
> immediately given the token and
> woken up, and further tokens will wake more consumers whether they are
> already waiting
> or not.
>
> Looks like a bug to me.

My point is that (http://en.wikipedia.org/wiki/Semaphore_(programming)):

P(Semaphore s) // Acquire Resource
{
   wait until s > 0, then s := s-1;
   /* Testing and decrementing s must be atomic to avoid race conditions */
}

V(Semaphore s) // Release Resource
{
   s := s+1; /* must be atomic */
}

P can only wake a single thread, because the semaphore count represents
the free resource count. The original post said:

"the post() unlocks only one of the 4 producers"

and that's logical. If there are 4 waiting threads, you need 4 posts to
unlock all.

Best,

Ion


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