pessimism.texi 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. @node Pessimistic concurrency
  2. @section Pessimistic concurrency
  3. @cindex mutual exclusion
  4. @cindex mutex locks
  5. @cindex locks for mutual exclusion
  6. While Scheme48's primitive thread synchronization mechanisms revolve
  7. around optimistic concurrency, Scheme48 still provides the more
  8. well-known mechanism of pessimistic concurrency, or mutual exclusion,
  9. with locks. Note that Scheme48's pessimistic concurrency facilities
  10. are discouraged, and very little of the system uses them (at the time
  11. this documentation was written, none of the system uses locks), and the
  12. pessimistic concurrency libraries are limited to just locks; condition
  13. variables are integrated only with optimistic concurrency. Except for
  14. inherent applications of pessimistic concurrency, it is usually better
  15. to use optimistic concurrency in Scheme48.
  16. @stindex locks
  17. These names are exported by the @code{locks} structure.
  18. @deffn procedure make-lock @returns{} lock
  19. @deffnx procedure lock? @returns{} boolean
  20. @deffnx procedure obtain-lock lock @returns{} unspecified
  21. @deffnx procedure maybe-obtain-lock lock @returns{} boolean
  22. @deffnx procedure release-lock lock @returns{} unspecified
  23. @code{Make-lock} creates a new lock in the `released' lock state.
  24. @code{Lock?} is the disjoint type predicate for locks.
  25. @code{Obtain-lock} atomically checks to see if @var{lock} is in the
  26. `released' state: if it is, @var{lock} is put into the `obtained' lock
  27. state; otherwise, @code{obtain-lock} waits until @var{lock} is ready to
  28. be obtained, at which point it is put into the `obtained' lock state.
  29. @code{Maybe-obtain-lock} atomically checks to see if @var{lock} is in
  30. the `released' state: if it is, @var{lock} is put into the `obtained'
  31. lock state, and @code{maybe-obtain-lock} returns @code{#t}; if it is in
  32. the `obtained' state, @code{maybe-obtain-lock} immediately returns
  33. @code{#f}. @code{Release-lock} sets @var{lock}'s state to be
  34. `released,' letting the next thread waiting to obtain it do so.
  35. @end deffn