|
Boost Users : |
From: Amerio (amerio_at_[hidden])
Date: 2004-12-22 17:38:29
Hello,
I'm lacking a boost semaphore, so I tried to roll my own.
Being carefull with threads, I present here my version, hoping you gurus
will spot any flaw.
class sem
{
sem(unsigned count): m_count(count) {}
void post()
{
boost::mutex::scoped_lock lock(m_mutex);
++m_count;
m_cond_.notify_one();
}
void wait()
{
boost::mutex::scoped_lock lock(m_mutex);
while ( m_count==0 ) m_cond.wait( lock );
--m_count;
}
private:
unsigned m_count;
boost::mutex m_mutex;
boost::condition m_cond;
};
Objective : I need a semaphore to sync many readers to a single input queue.
If you know another implementation or solution to this specific problem,
your help is welcome.
Thank you.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net