From: ts Date: 2001-12-06T20:34:05+09:00 Subject: [ruby-talk:27673] Re: Behaviour of Mutex >>>>> "M" == Max Maischein writes: M> So, if anyone can enlighten me about the reason for the current Mutex M> behaviour, or point me to an implementation that does What I Want, or M> tell me that I should write it, I'm happy :-)) You have try_lock Well you are in a special case, try it in a thread pigeon% cat b.rb #!/usr/bin/ruby require 'thread' # This is the problem lock = Mutex.new a = Thread.new do p "First synchronize" lock.synchronize { p "Second synchronize" lock.synchronize { p "Two times synchronized" } p "One time synchronized" } p "Done." end a.join pigeon% pigeon% b.rb "First synchronize" "Second synchronize" deadlock 0x401c0528: 2:8 (main) - ./b.rb:20 deadlock 0x401b6230: 2:0 - /usr/local/lib/ruby/1.6/thread.rb:60 /usr/local/lib/ruby/1.6/thread.rb:60: Thread: deadlock (fatal) pigeon% Look at pthread_mutex_lock (3) for the different kind of mutex (`fast' which give a deadlock, `error checking' which give an error, `recursive' which allow the same thread to call many times lock, ...) Guy Decoux