Mutex: Difference between revisions

Content added Content deleted
(This is not written as a task.)
Line 641: Line 641:
If the channel is empty, a task will wait until an object is available into the channel.
If the channel is empty, a task will wait until an object is available into the channel.


<lang Oforth>func: job(mut)
<lang Oforth>import: parallel

{
: job(mut)
mut receive drop
mut receive drop
"I get the mutex !" println
"I get the mutex !" .
System sleep(2000)
2000 sleep
"Now I release the mutex" println
"Now I release the mutex" println
mut send(1) drop
1 mut send drop ;
}
: mymutex

func: mymutex
{
| mut |
| mut |
Channel new dup send(1) drop ->mut
Channel new dup send(1) drop ->mut
#[ #[ job(mut) ] & ] times(10)
10 #[ #[ mut job ] & ] times ;</lang>
}</lang>


=={{header|Oz}}==
=={{header|Oz}}==