Forum Navigation
unexpected sync.Condition behaviors
Moderators:
kris
Posted: 12/07/09 18:49:07The first thing I was surprised by but now I'm not sure if it is expected behavior is that the mutex associated with the Condition has to be held before calling Condition.wait or wait will never return (e.g. if the synchronized statement in the example below is removed "Thread A" will only be printed once).
The second, is that the example below throws an OutOfMemoryException? shortly after the first condition.notify call is made. I don't understand what might be causing this.
import tango.core.Thread; import tango.core.sync.Mutex; import tango.core.sync.Condition; import tango.io.Stdout; Mutex mutex; Condition condition; void run() { while(true) { synchronized (mutex) { Stdout("Thread A").newline; condition.wait(1); } } } void main(char[][] args) { mutex = new Mutex(); condition = new Condition(mutex); auto a = new Thread(&run); a.start(); while(true) { Thread.sleep(5); Stdout("Main thread").newline; condition.notify(); } }












