Next: Custom thread synchronization, Previous: Concurrent ML, Up: Multithreading
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.
Make-lockcreates a new lock in the `released' lock state.Lock?is the disjoint type predicate for locks.Obtain-lockatomically checks to see if lock is in the `released' state: if it is, lock is put into the `obtained' lock state; otherwise,obtain-lockwaits until lock is ready to be obtained, at which point it is put into the `obtained' lock state.Maybe-obtain-lockatomically checks to see if lock is in the `released' state: if it is, lock is put into the `obtained' lock state, andmaybe-obtain-lockreturns#t; if it is in the `obtained' state,maybe-obtain-lockimmediately returns#f.Release-locksets lock's state to be `released,' letting the next thread waiting to obtain it do so.