condition::notify_[whatever] overhead

21 May
2004
21 May
'04
10:03 a.m.
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();
7695
Age (days ago)
7695
Last active (days ago)
0 comments
1 participants
participants (1)
-
Vadim Senchukov