.true if the current activity has already owned or has
just acquired the mutex semaphore.
Returns .false if the mutex is owned by a different activity, or a
timeout has occurred.
acquire
increasing the mutex nesting level by one.
An equivalent number of calls to
release
are needed to make the mutex available again to another activity.
acquire suspends the current activity
until it can get ownership of the mutex.
acquire immediately returns .true if the mutex
was acquired, or .false otherwise.
acquire suspends the current activity
for timeout seconds or until the
current activity can acquire the mutex, whatever comes first.
mutex = .MutexSemaphore~new
.Task~new~startWork(mutex, "work 1")
.Task~new~startWork(mutex, "work 2")
say "work tasks started"
::class Task
::method startWork unguarded
expose mutex name
use strict arg mutex, name
reply
self~doWork(1)
::method doWork unguarded
expose mutex name
use strict arg level
-- five levels of nested acquires
if level > 5 then
return
mutex~acquire
say name level
self~doWork(level + 1)
work tasks started
work 2 1
work 2 2
work 2 3
work 2 4
work 2 5
work 1 1
work 1 2
work 1 3
work 1 4
work 1 5