Previous: Low level thread primitives, Up: Threads


32.4.2 Higher level thread procedures

Higher level thread procedures are available by evaluating:

     (use-modules (ice-9 threads))

The following procedures and macros provide standardized thread creation and mutex interaction.

— Scheme Procedure: %thread-handler tag [args...]

This procedure is specified as the standard error-handler for make-thread and begin-thread. If the number of args is three or more, use display-error, otherwise display a message "uncaught throw to tag". All output is sent to the port specified by current-error-port.

Before display, global var the-last-stack is set to #f and signals are unmasked with unmask-signals.

[FIXME: Why distinguish based on number of args?! Cue voodoo music here.]

— Scheme Macro: make-thread proc [args...]

Apply proc to args in a new thread formed by call-with-new-thread using %thread-handler as the error handler.

— Scheme Macro: begin-thread first [rest...]

Evaluate forms first and rest in a new thread formed by call-with-new-thread using %thread-handler as the error handler.

— Scheme Macro: with-mutex m [body...]

Lock mutex m, evaluate body, and then unlock m. These sub-operations form the branches of a dynamic-wind.

— Scheme Macro: monitor first [rest...]

Evaluate forms first and rest under a newly created anonymous mutex, using with-mutex.

[FIXME: Is there any way to access the mutex?]