I would like to know what are ruby's alternatives to the Java methods :
Could you please post a small snippet or some links ?
What you are looking for is ConditionVariable
in Thread
:
require "thread"
m = Mutex.new
c = ConditionVariable.new
t = []
t << Thread.new do
m.synchronize do
puts "A - I am in critical region"
c.wait(m)
puts "A - Back in critical region"
end
end
t << Thread.new do
m.synchronize do
puts "B - I am critical region now"
c.signal
puts "B - I am done with critical region"
end
end
t.each {|th| th.join }
With the caveat that I don't know Java, based on your comments, I think that you want a condition variable. Google for "Ruby condition variable" comes up with a bunch of useful pages. The first link I get, seems to be a nice quick introduction to condition vars in particular, while this looks like it gives a much broader coverage of threaded programming in Ruby.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With