MzScheme supports multiple threads of control within a program. Threads are implemented for all operating systems, even when the operating system does not provide primitive thread support.
(thread thunk) invokes the procedure thunk with no arguments in a new thread of control. The thread procedure returns immediately with a thread descriptor value. When the invocation of thunk returns, the thread created to invoke thunk terminates.
Example:
(thread (lambda () (sleep 2) (display 7) (newline))) ; => a thread descriptor
; displays 7 after two seconds pass
Each thread has its own parameter settings (see section 9.4), such as the current directory or current exception handler. A newly-created thread inherits the parameter settings of the creating thread, except
When a thread is created, it is placed into the management of the current custodian (See section 9.5). A thread that has not terminated can be ``garbage collected'' only if it is unreachable and blocked on an unreachable semaphore.