diff options
author | Jim Carroll <thecarrolls@jiminger.com> | 2011-07-15 11:20:10 -0400 |
---|---|---|
committer | Jim Carroll <thecarrolls@jiminger.com> | 2011-07-15 13:48:37 -0400 |
commit | a51927c31fc3e30d11f25c052a28a710e951dbdf (patch) | |
tree | a0e87adbe3d993ed3fb98525c721b9ece2ef1d99 | |
parent | 8c0d7e0cd50cd469e545bb171b0316237a5b6887 (diff) |
Fix for locking the predicate change in the set method.
Thanks to @FernetMenta for pointing out the issue with setting the without holding the lock predicate. It's possible that the predicate is changed between the check and the wait() in the Wait* call. This fixes that problem.
-rw-r--r-- | xbmc/threads/Event.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/xbmc/threads/Event.cpp b/xbmc/threads/Event.cpp index adaa490678..d658cc463b 100644 --- a/xbmc/threads/Event.cpp +++ b/xbmc/threads/Event.cpp @@ -58,8 +58,16 @@ void CEvent::removeGroup(XbmcThreads::CEventGroup* group) // CEvent::groupListMutex -> CEventGroup::mutex -> CEvent::mutex void CEvent::Set() { - // no locking necessary - signaled = true; + // Originally I had this without locking. Thanks to FernetMenta who + // pointed out that this creates a race condition between setting + // checking the signal and calling wait() on the Wait call in the + // CEvent class. This now perfectly matches the boost example here: + // http://www.boost.org/doc/libs/1_41_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref + { + CSingleLock slock(mutex); + signaled = true; + } + condVar.notifyAll(); CSingleLock l(groupListMutex); |