|
Boost : |
From: Vadim Senchukov (bigwad_at_[hidden])
Date: 2004-05-21 05:03:55
On Win32 platform both notify_one and notify_all do a lot of work with
kernel objects whether there are any threads waiting on
condition or no.
Can't we eliminate such overhead using pretty simple counter of waitng
threads like in code below? Or I've overlooked smth and code has subtle
problems?
boost::mutex mtx;
boost::condition cond;
int waiting = 0;
...
//waiting in some place
boost::mutex::scoped_lock lk( mtx );
++waiting;
while (!pred)
cond.wait( lk );
--waiting;
//notification in another place
boost::mutex::scoped_lock lk( mtx );
if ( waiting )
cond.notify_one();
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk