On Sep 9, 2010, at 09:22, Sergio L. wrote:
I am having trouble with threading in Ruby.
My code outputs: `synchronize’: stopping only thread (ThreadError).
What does this mean and what could the cause of this error be?!
It means that you have a deadlock situation, where one thread is
waiting for a resource that will never be released.
My ruby (1.8.7) gives a slightly different error when I try this but
take this example:
mutex = Mutex.new
mutex.synchronize do # (1) lock the mutex
mutex.synchronize do # Wait for the mutex to become available
then lock it
end # unlock the mutex locked by (1)
The inner “synchronize” is waiting for the mutex lock, but it will
never get it, because the mutex will only get unlocked when the outer
I have a method named p, defined as follows:
If the block you’re passing into this method tries to lock the mutex,
either directly or by calling synchronize, you’ll get deadlock. The
block you pass will be trying to lock the mutex, but the mutex is
already locked by the ‘p’ method. By the way, you might not want to
call your method ‘p’ because ‘p’ is already a well-known, often-used