From: Bill Kelly Date: 2004-08-27T11:11:57+09:00 Subject: Re: [BUG?] erroneous deadlock? (was: apparent hang...) Hello once again, > Hopefully have this figured out soon. Er. Well I was hoping all this wouldn't turn out to be ENTIRELY in my code... It appears the problem is with my wait/timeout code: def global_wait(timeout_secs) begin alarm_th = Thread.start { sleep timeout_secs $global_signal.broadcast } $global_mutex.synchronize { ############## if alarm_th's broadcast happens ############## before we get to the wait here, ############## then, obviously, we may never wake up $global_signal.wait($global_mutex) } ensure alarm_th.kill if alarm_th and alarm_th.alive? end end As a workaround, I've changed it to: def global_wait(timeout_secs) begin awake = false alarm_th = Thread.start { sleep timeout_secs while not awake $global_signal.broadcast sleep(0.001) # WAS: Thread.pass end } $global_mutex.synchronize { $global_signal.wait($global_mutex) awake = true } ensure alarm_th.kill if alarm_th and alarm_th.alive? end end ...So the alarm thread sticks around until it's *sure* the primary thread has awakened. I guess it's pretty cheesy, with the sleep(0.001) and all... But as long as it's foolproof, it will work for my purposes. I'm now wondering if I should add any begin/rescue in the alarm thread, in case #broadcast could ever raise an exception.... This code will be in a server that I want to run indefinitely, with no problems... :) Thanks everyone who followed the thread; sorry if I've wasted your time . . . Regards, Bill