From: Michael Malone Date: 2009-03-19T03:59:47+09:00 Subject: Re: does IO.read block? Robert Klemme wrote: > Here's another pastie that demonstrates a common error causing a deadlock: > > http://pastie.org/419533 > > Cheers > > robert > > Thanks, but I have a new theory. I broke everything down to be as atomic as possible, which included pulling in the Synchronised Queue from thread.rb and modifying it slightly to lock the mutex then unlock when necessary, so blocks were being passed as parameters as little as possible. (As they are quite removed from being an atomic operation). And very nearly immediately, ruby's deadlock protection kicked in. What happens is this: In the main thread, I create the jobs and put them on the queue. Depending on how things run (why it only happens sometimes) if the worker threads are scheduled more favourably, then they will complete, but not die (as they are blocking on queue, waiting for new jobs) meaning that each thread, except for the main thread is asleep. I then call join() in the main thread meaning the main thread sleeps before the others have a chance to wakeup and finish, at which point ruby detects a deadlock, even though its next operation should be to wakeup a new thread. At this point a "Bug Report: Unlocking mutex must be NULL" is generated by the interpreter and then hastily exits. As soon as I have a smaller, specific case I will be filing a bug report. Thanks for all your help, but I think I have it now. Michael ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. =======================================================================