Hi, 2010/5/6 Caleb Clausen <vikkous / gmail.com>: > AFAICT, Silvain's proposed fix is mostly correct. I've made a couple > of minor revisions below: the rescue clause should read 'rescue > Exception' to ensure the cleanup happens on all exceptions, and I've > added a raise at the end so the exception will be re-raised rather > than having a normal return. Silvain, (or Yusuke, or anyone) please do > correct me if either of these is wrong. BTW, what behavior do you expect when an exception is raised during ConditionVariable#wait? Currently, the call to CV#wait may aborted *without* locking the corresponding mutex: require "thread" m = Mutex.new cv = ConditionVariable.new th = Thread.new do m.synchronize do begin cv.wait(m) ensure sleep 0.5 p m.locked? #=> false, expceted true break end end end sleep 0.5 m.lock th.raise th.raise m.unlock th.join This is a serious issue, but if this is fixed to ensure to lock the mutex by ignoring an exception, the process can not be stopped by Ctrl+C. It is another serious issue. I guess there is no answer satisfying everbody, but I think we should accept the fact that Thread#raise is not in line with CV. In addition, if we are really serious for using CV, signal must not be converted to an exception, such as SIGINT and Interrupted. It can be achieved by Kernel#trap, i.e., trap(:INT) {}, but it is too stoic to enjoy programming... > Am I the only one who likes semaphores? Silvain, I'm particularly > interested in hearing your opinion. Would a semaphore have suited your > purposes as well as a condvar does? Agreed. CV is too difficult. -- Yusuke Endoh <mame / tsg.ne.jp>