Boost logo

Boost :

From: Gregory Dai (gregory.dai_at_[hidden])
Date: 2007-05-06 14:45:10


On 5/6/07, Yuval Ronen <ronen_yuval_at_[hidden]> wrote:

<snip>

namespace boost {
>
> class semaphore
> {
> public:
> semaphore(std::size_t count) : m_count(count), m_mutex(),
> m_condition() { }
>
> void lock()
> {
> mutex::scoped_lock sl(m_mutex);
> while (m_count == 0)
> m_condition.wait(sl);
> assert(m_count > 0);
> m_count--;
> }
>
> void unlock()
> {
> mutex::scoped_lock sl(m_mutex);
> m_count++;
> m_condition.notify_one();
> }
>
> private:
> std::size_t m_count;
> mutex m_mutex;
> condition m_condition;
> };
>
> } // namespace boost

<snip>

Could we use more conventional method names such as wait() and post()
instead of lock() and unlock(), please? Even acquire() and release() sound
better. In addition, I'd suggest two more member methods:
try_wait/try_acquire(size_t timeout) and count().

Greg


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