Next: , Up: Multithreading


5.1 Basic thread operations

This section describes the threads structure.

— procedure: spawn thunk [name] –> thread

Spawn constructs a new thread and instructs the current thread scheduler to commence running the new thread. Name, if present, is used for debugging. The new thread has a fresh dynamic environment.

There are several miscellaneous facilities for thread operations.

— procedure: relinquish-timeslice –> unspecified
— procedure: sleep count –> unspecified

Relinquish-timeslice relinquishes the remaining quantum that the current thread has to run; this allows the current scheduler run the next thread immediately. Sleep suspends the current thread for count milliseconds.

— procedure: terminate-current-thread –> (does not return)

Terminates the current thread, running all dynamic-wind exit points. Terminate-current-thread obviously does not return.

Threads may be represented and manipulated in first-class thread descriptor objects.

— procedure: current-thread –> thread
— procedure: thread? object –> boolean
— procedure: thread-name thread –> value
— procedure: thread-uid thread –> unique-integer-id

Current-thread returns the thread descriptor for the currently running thread. Thread? is the thread descriptor disjoint type predicate. Thread-name returns the name that was passed to spawn when spawning thread, or #f if no name was passed. Thread-uid returns a thread descriptor's unique integer identifier, assigned by the thread system.