How write a synchronized class

  • Thread starter Guillaume dorchies
  • Start date
G

Guillaume dorchies

Hello

How do to write a synchronized class like in java for Ruby

I try with a Mutex but if a method call another method of the same
instance I obtain a Deadlock.


Thanks
Guillaume
 
T

Tim Pease

Hello

How do to write a synchronized class like in java for Ruby

I try with a Mutex but if a method call another method of the same
instance I obtain a Deadlock.

I wrote a reentrant mutex class at one point in time ...

http://gist.github.com/108117

Give it a shot and see if it fixes your deadlock issue.

Blessings,
TwP
 
R

Robert Klemme

2009/5/7 Tim Pease said:
I wrote a reentrant mutex class at one point in time ...

http://gist.github.com/108117

Give it a shot and see if it fixes your deadlock issue.

Sorry, but you could have saved yourself the effort because it's part
of the standard library:

17:45:59 $ ruby19 -r monitor -e 'm=Monitor.new;m.synchronize {
m.synchronize { p 1 } }'
1
17:46:05 $ ruby19 -r thread -e 'm=Mutex.new;m.synchronize {
m.synchronize { p 1 } }'
<internal:prelude>:6:in `lock': deadlock; recursive locking (ThreadError)
from <internal:prelude>:6:in `synchronize'
from -e:1:in `block in <main>'
from <internal:prelude>:8:in `synchronize'
from -e:1:in `<main>'
17:46:17 $ ruby19 -r monitor -e 'm=Monitor.new;m.synchronize {
m.synchronize { p 1 } }'
1
17:46:23 $

Kind regards

robert
 

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,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top