Boost logo

Boost :

Subject: Re: [boost] [Interprocess::Semaphore] Deadlock on more producers - one consumer problem
From: James Mansion (james_at_[hidden])
Date: 2009-06-19 15:03:10

igaztanaga_at_[hidden] wrote:
> My point is that (
> 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.
The post operation that 'wakes up' is V, not P.

If your api allows V(4) to release 4 resources atomically, then 4
consumers in P must be released (if they are
waiting, and any left over accrued to allow future consumers not to
block. Even if you say V(4) is not supported
and actually V;V;V;V and these are atomic individually, then there is
still a race between those four posts
and any Ps actually getting to run. Either way, you MUST enable 4-off
Ps to become ready. If the API allows to
post multiple resources atomically, then you need to handle this.

Boost list run by bdawes at, gregod at, cpdaniel at, john at