`synchronize': stopping only thread

  • Thread starter Sergio Lombrico
  • Start date
S

Sergio Lombrico

Hi.

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?!
I have a method named p, defined as follows:

@mutex.synchronize do
db_open
yield(@db)
db_close
end

...p gets called with a block which uses db.

Cheers,

Sergio
 
B

Ben Giddings

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
puts "hi"
end
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
synchronize finishes.
I have a method named p, defined as follows:

@mutex.synchronize do
db_open
yield(@db)
db_close
end

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
method.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top