Next: , Previous: Continuation Barriers, Up: Scheduling


5.17.4 Threads

— Scheme Procedure: all-threads
— C Function: scm_all_threads ()

Return a list of all threads.

— Scheme Procedure: current-thread
— C Function: scm_current_thread ()

Return the thread that called this function.

— Scheme Procedure: call-with-new-thread thunk handler

Call thunk in a new thread and with a new dynamic state, returning the new thread. The procedure thunk is called via with-continuation-barrier.

When handler is specified, then thunk is called from within a catch with tag #t that has handler as its handler. This catch is established inside the continuation barrier.

Once thunk or handler returns, the return value is made the exit value of the thread and the thread is terminated.

— C Function: SCM scm_spawn_thread (scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)

Call body in a new thread, passing it body_data, returning the new thread. The function body is called via scm_c_with_continuation_barrier.

When handler is non-NULL, body is called via scm_internal_catch with tag SCM_BOOL_T that has handler and handler_data as the handler and its data. This catch is established inside the continuation barrier.

Once body or handler returns, the return value is made the exit value of the thread and the thread is terminated.

— Scheme Procedure: join-thread thread

Wait for thread to terminate and return its exit value. Threads that have not been created with call-with-new-thread or scm_spawn_thread have an exit value of #f.

— Scheme Procedure: thread-exited? thread
— C Function: scm_thread_exited_p (thread)

Return #t iff thread has exited.

— Scheme Procedure: yield

If one or more threads are waiting to execute, calling yield forces an immediate context switch to one of them. Otherwise, yield has no effect.

Higher level thread procedures are available by loading the (ice-9 threads) module. These provide standardized thread creation.

— macro: make-thread proc [args...]

Apply proc to args in a new thread formed by call-with-new-thread using a default error handler that display the error to the current error port. The args... expressions are evaluated in the new thread.

— macro: begin-thread first [rest...]

Evaluate forms first and rest in a new thread formed by call-with-new-thread using a default error handler that display the error to the current error port.