From: Yusuke ENDOH Date: 2010-03-20T03:20:24+09:00 Subject: [ruby-core:28803] Re: [Bug #2629] ConditionVariable#wait(mutex, timeout) should return whether the condition was signalled, not the waited time Hi, 2010/3/17 Yusuke Endoh : > I could be wrong because I'm not familiar with multi-thread programming, > but I doubt that it is potentially dangerous to depend on the reason of > wait termination. Couldn't it cause race condition? > > I have no idea about concrete race scenario, but there is a circumstance > where Java's Object#wait seems not to return the termination reason. I found ptherad_cond_timedwait returns ETIMEOUT. My concern seemed to be needless fear. But I still doubt a little whether your code has a race: http://www.opengroup.org/onlinepubs/000095399/functions/pthread_cond_timedwait.html > Similarly, when pthread_cond_timedwait() returns with the timeout error, > the associated predicate may be true due to an unavoidable race between > the expiration of the timeout and the predicate state change. > > The application needs to recheck the predicate on any return because it > cannot be sure there is another thread waiting on the thread to handle > the signal, and if there is not then the signal is lost. The burden is > on the application to check the predicate. And I realized a bigger problem from the document; it is considered as a race to speficy a relative time as timeout. ConditionVariable#wait should accept an absolute time, at least. But it needs Mutex#sleep accept Time instead of Integer. Umm. -- Yusuke ENDOH