
20 Jun
2009
20 Jun
'09
9:21 p.m.
2009/6/20 Ion Gaztañaga <igaztanaga@gmail.com>:
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.