Mutex: Difference between revisions

Content added Content deleted
(Nimrod -> Nim)
Line 625: Line 625:
Mutex.unlock m;</lang>
Mutex.unlock m;</lang>

=={{header|Oforth}}==

Oforth has no mutex.
A mutex can be simulated using a channel initialized with one object.
A task can receive the object from the channel (get the mutex) and send it to the channel when the job is done.
If the channel is empty, a task will wait until an object is available into the channel.

<lang Oforth>func: job(mut)
{
mut receive drop
"I get the mutex !" println
System sleep(2000)
"Now I release the mutex" println
mut send(1) drop
}

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


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