Pessimistic concurrency
=======================

While Scheme48's primitive thread synchronization mechanisms revolve around optimistic concurrency, Scheme48 still provides the more well-known mechanism of pessimistic concurrency, or mutual exclusion, with locks.  Note that Scheme48's pessimistic concurrency facilities are discouraged, and very little of the system uses them (at the time this documentation was written, none of the system uses locks), and the pessimistic concurrency libraries are limited to just locks; condition variables are integrated only with optimistic concurrency.  Except for inherent applications of pessimistic concurrency, it is usually better to use optimistic concurrency in Scheme48.

These names are exported by the locks structure.

 -- procedure: make-lock returns lock
 -- procedure: lock? returns boolean
 -- procedure: obtain-lock lock returns unspecified
 -- procedure: maybe-obtain-lock lock returns boolean
 -- procedure: release-lock lock returns unspecified
     Make-lock creates a new lock in the `released' lock state. Lock? is the disjoint type predicate for locks. Obtain-lock atomically checks to see if LOCK is in the `released' state: if it is, LOCK is put into the `obtained' lock state; otherwise, obtain-lock waits until LOCK is ready to be obtained, at which point it is put into the `obtained' lock state. Maybe-obtain-lock atomically checks to see if LOCK is in the `released' state: if it is, LOCK is put into the `obtained' lock state, and maybe-obtain-lock returns #t; if it is in the `obtained' state, maybe-obtain-lock immediately returns #f.  Release-lock sets LOCK's state to be `released,' letting the next thread waiting to obtain it do so.