condition_variable::notify_all and notify_one don't require lock to be locked

condition_variable::notify_all and notify_one don't require lock to be locked

Post by itaj sherm » Sun, 09 Jan 2011 04:17:11


condition_variable::notify_all doesn't require lock to be locked. But,
if it did, or if there was a version that would require lock be locked
(say locked_notify_all). Woudn't then calling locked_notify_all in
places where lock is locked, be more efficient?

My specific thought is: when calling notify_all, and there are
currently no other threads blocked on the condition_variable, the
function has no side effects. But the problem is, that if this
function doesn't know whether the lock is locked, it has to do at
least one atomic consume load to check that. A function like
locked_notify_all, can assume the lock is locked, and could verify
that there are no blocked threads without any synchronizing operations
(no locking no atomics), and that would have better performance.

Same goes for notify_one.

Is that right?

itaj


--
[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]