Condition variables take a bit of getting used to. There are standard idioms that you need to use. "signal" only releases threads that are waiting at that time so you need to make sure the thread you want to wake up is actually waiting.

In your example you need to lock the mutex before the fork and then, inside foo, lock it before you call "signal" and unlock it afterwards. In this way "foo" will only be able to proceed when the mutex is atomically unlocked by the wait call.

David

On 24/10/2016 07:43, Kostirya wrote:
Hello.
Tell me, please, how to use the Thread and ConditionVar.

The following code unpredictably hangs up...

open Thread
open Thread Mutex ConditionVar

val cv = conditionVar()
and m = mutex();

fun foo() = ( print  "OK\n"; signal cv );
fork(foo, [EnableBroadcastInterrupt true, InterruptState InterruptSynch]);

wait(cv, m);
print "The End\n";

Nick.

P.S.
I use fixes-5.6 git version PolyML.
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to