Guile supports POSIX threads, unless it was configured with
--without-threads or the host lacks POSIX thread support. When
thread support is available, the threads feature is provided
(see provided?).
The procedures below manipulate Guile threads, which are wrappers around the system's POSIX threads. For application-level parallelism, using higher-level constructs, such as futures, is recommended (see Futures).
Return the thread that called this function.
Call
thunkin a new thread and with a new dynamic state, returning the new thread. The procedure thunk is called viawith-continuation-barrier.When handler is specified, then thunk is called from within a
catchwith tag#tthat 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.
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 viascm_internal_catchwith tagSCM_BOOL_Tthat 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.
Return
#tiff obj is a thread; otherwise, return#f.
Wait for thread to terminate and return its exit value. Threads that have not been created with
call-with-new-threadorscm_spawn_threadhave an exit value of#f. When timeout is given, it specifies a point in time where the waiting should be aborted. It can be either an integer as returned bycurrent-timeor a pair as returned bygettimeofday. When the waiting is aborted, timeoutval is returned (if it is specified;#fis returned otherwise).
Return
#tiff thread has exited.
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.
Asynchronously notify thread to exit. Immediately after receiving this notification, thread will call its cleanup handler (if one has been set) and then terminate, aborting any evaluation that is in progress.
Because Guile threads are isomorphic with POSIX threads, thread will not receive its cancellation signal until it reaches a cancellation point. See your operating system's POSIX threading documentation for more information on cancellation points; note that in Guile, unlike native POSIX threads, a thread can receive a cancellation notification while attempting to lock a mutex.
Set proc as the cleanup handler for the thread thread. proc, which must be a thunk, will be called when thread exits, either normally or by being canceled. Thread cleanup handlers can be used to perform useful tasks like releasing resources, such as locked mutexes, when thread exit cannot be predicted.
The return value of proc will be set as the exit value of thread.
To remove a cleanup handler, pass
#ffor proc.
Return the cleanup handler currently installed for the thread thread. If no cleanup handler is currently installed, thread-cleanup returns
#f.
Higher level thread procedures are available by loading the
(ice-9 threads) module. These provide standardized
thread creation.