I would like to know what are ruby's alternatives to the Java methods :
- wait
- notify
- notifyAll
Could you please post a small snippet or some links ?
I would like to know what are ruby's alternatives to the Java methods :
Could you please post a small snippet or some links ?
There's no equivalent to notifyAll(), but the other two are
Thread.stop
(stops the current thread) andrun
(called on a stopped thread to make it start going again).What you are looking for is
ConditionVariable
inThread
: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.
I think what you want is
Thread#join
I think you're looking for something more like this. It'll work on any object instantiated after this gets executed. It's not perfect, particularly where Thread.stop is outside the mutex. In java, waiting on a thread, releases a monitor.