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 f) invokes the thunk f in a new thread of control. The thread procedure returns immediately with a thread descriptor value. When the thunk f returns, the thread created to invoke f terminates.
Example:
(thread (lambda () (sleep 2) (display 7) (newline))) ; => a thread descriptor
; displays 7 after 2 seconds pass
Each thread has its own exception handler (see section 2.23) and error escape handler (see section 3.13).
In applications that use MzScheme with a top-level event loop (MrEd is such an application), the main thread is special. The main thread is invoked in to handle user events; while each event is handled, pending events are blocked until the event handling is completed. (A thread can be explicitly spawned to handle any event asynchronously, but each event is received from the queue synchronously.) The main thread can be interrupted at any time to service an event-based callback; during such an interruption, the main thread's current continuation is suspended until the callback is completed.