Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How write a synchronized class

Reply
Thread Tools

How write a synchronized class

 
 
Guillaume dorchies
Guest
Posts: n/a
 
      05-07-2009
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Tim Pease
Guest
Posts: n/a
 
      05-07-2009
On Thu, May 7, 2009 at 6:38 AM, Guillaume dorchies
<(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
 
Guillaume dorchies
Guest
Posts: n/a
 
      05-07-2009
Thank you It's exactly that I need



--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      05-07-2009
2009/5/7 Tim Pease <(E-Mail Removed)>:
> On Thu, May 7, 2009 at 6:38 AM, Guillaume dorchies
> <(E-Mail Removed)> wrote:
>> 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.


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 } }'
<internalrelude>:6:in `lock': deadlock; recursive locking (ThreadError)
from <internalrelude>:6:in `synchronize'
from -e:1:in `block in <main>'
from <internalrelude>: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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Synchronized Block v.s. Synchronized Method Jerry Java 4 08-11-2010 02:34 PM
Question on synchronized and non synchronized methods ankur Java 4 11-28-2008 09:56 PM
synchronized block in synchronized static method dmcreyno Java 9 06-27-2006 07:43 PM
Use of synchronized variables over synchronized methods? Pep Java 6 08-15-2005 01:29 PM



Advertisments