Mutual-exclusion locks

Next:Read-write locks

A mutual-exclusion lock ensures that only one thread executes with the lock held at a time. They are used to protect critical sections so that certain operations appear to be atomic to other threads.

There are two varieties of locks: non-reentrant and reentrant. The latter may be acquired recursively by the same thread. Attempting to do so with the former will deadlock.

<lock> ( -- lock )

<reentrant-lock> ( -- lock )

with-lock ( lock quot -- )

with-lock-timeout ( lock timeout quot -- )