See Original text in context
method condition(Lock: )
Returns a condition variable as a Lock::ConditionVariable
object. Check this article or the Wikipedia for background on condition variables and how they relate to locks and mutexes.
my = Lock.new;.condition;
You should use a condition over a lock when you want an interaction with it that is a bit more complex than simply acquiring or releasing the lock.
constant ITEMS = 100;my = Lock.new;my = .condition;my = 0;my = 0;my = 1..ITEMS;my = 0 xx ITEMS;loop ( my = 0; < ; ++ ).protect();say .map: ;# OUTPUT: «2* 5* 10 17* 26 37* 50 65 82 101* … »
In this case, we use the condition variable $cond
to wait until all numbers have been generated and checked and also to .signal
to another thread to wake up when the particular thread is done.
See Original text in context
method condition(--> Str)
Returns the part of the source code that describes the phaser condition.