Mutex: Difference between revisions

Content added Content deleted
(J)
Line 699: Line 699:


</lang>
</lang>

=={{header|J}}==

J904 introduces mutexes.

Note: currently J mutexes do not have a meaningful display representation.

<lang J> name=. 10 T. 0 NB. create an exclusive mutex
name=. 10 T. 1 NB. create a shared (aka "recursive") mutex
failed=. 11 T. mutex NB. take an exclusive lock on a mutex (waiting forever if necessary)
failed=. 11 T. mutex;seconds NB. try to take an exclusive lock on a mutex but may time out
NB. failed is 0 if lock was taken, 1 if lock was not taken
13 T. mutex NB. release lock on mutex</lang>

Recursive mutexes may be locked multiple times -- successive locks increase a counter. When unlocked as many times as previously locked, the mutex is released.

Exclusive mutexes will suspend (waiting "forever" if necessary) if the lock was already taken.


=={{header|Java}}==
=={{header|Java}}==