Mutual exclusion support
========================
This manual section was written by Moshe Zadka
<moshez@zadka.site.co.il>.
Lock and queue for mutual exclusion.
The `mutex' module defines a class that allows mutual-exclusion via
acquiring and releasing locks. It does not require (or imply) threading
or multi-tasking, though it could be useful for those purposes.
The `mutex' module defines the following class:
`mutex()'
Create a new (unlocked) mutex.
A mutex has two pieces of state -- a "locked" bit and a queue.
When the mutex is not locked, the queue is empty. Otherwise, the
queue contains zero or more `(FUNCTION, ARGUMENT)' pairs
representing functions (or methods) waiting to acquire the lock.
When the mutex is unlocked while the queue is not empty, the first
queue entry is removed and its `FUNCTION(ARGUMENT)' pair called,
implying it now has the lock.
Of course, no multi-threading is implied - hence the funny
interface for `lock()', where a function is called once the lock is
acquired.