Boost logo

Boost :

Subject: Re: [boost] [threads] wait() and signal() ?
From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2009-10-07 12:41:18


Gottlob Frege wrote:
> If boost threads doesn't have a semaphore, we could add one.

boost::thread doesn't have a semaphore for a purpose.
boost::threads is modelled after the pthreads API, which does not
need what you are seeking for. Perhaps you could look up a book
on pthreads for an in depth explanation? For short in pthreads API the
state and the notification are decoupled, which is a more general
aproach.

Of course you know it, but it is straight forward to get the
equivalent of a semaphore with boost::threads.

Something like (details omitted):

mutex mx;
int count = 42;
codition c;

...
//acquire
{
    lock(mx);
    while (0==count) c.wait(mx);
    --count;
}

...
//release
{
    lock(mx);
    ++count;
    c.notify_all();
}

Regards, Roland

-- 
_________________________________________
  _  _  | Roland Schwarz aka. speedsnail
 |_)(_  | sip:speedsnail_at_[hidden]
 | \__) | mailto:roland.schwarz_at_[hidden]
________| http://www.blackspace.at

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