Signalling a conditional variable



  • There is one aspect of the various flow control systems (mutexes, events, conditionals, etc.) I've never quite understood (probably never having taken a CompSci class) which is why conditional variables can be signalled to release a single thread. I've never, not even once, stumbled upon a reason to use this feature instead of broadcast; in what kind of situation might it be useful?



  • Broadcast works correctly, but waking only one thread is more efficient if only one thing has been added to a work queue.  In the other case, many threads wake up, one of them gets the contents of the queue, and the rest just get nothing and go to sleep again.  Waking up, detecting that there's no work left, and going back to sleep isn't particularly expensive, but it isn't free and it delays the actualy work.





  • I see, it's an optimization for systems with limited parallel design...



  • @nexekho said:

    I see, it's an optimization for systems with limited parallel design...

    not it is an optimization for any system.  don't wake sleeping dragons unless you have something to feed them.


Log in to reply