|
Boost : |
Subject: Re: [boost] [Interprocess::Semaphore] Deadlock on more producers - one consumer problem
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-06-20 17:21:37
2009/6/20 Ion Gaztañaga <igaztanaga_at_[hidden]>:
> Cosimo Calabrese wrote:
>
>> inline void interprocess_semaphore::post()
>> {
>> scoped_lock<interprocess_mutex> lock(m_mut);
>> if(m_count == 0){
>> m_cond.notify_one();
>> }
>> ++m_count;
>> }
>
> Yes, I think you are right. post() should unconditionally notify_one(),
> otherwise, we could post() several times and only wake up one thread.
>
> Can you test your code removing the m_count == 0 condition?
Sorry for jumping into the middle of this. But shouldn't it only
notify_one() if count is greater than or equal to 0? Not
unconditionally. It's possible to initialize the semaphore with a
negative count, and in that case a call to wait() should not unblock
until the semaphore is 0 or higher.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk