Next: Higher level thread procedures, Up: Threads
[fixme: this takes args: thunk error-handler]
Evaluate
(thunk)in a new thread, and new dynamic context, returning a new thread object representing the thread.If an error occurs during evaluation, call error-handler, passing it an error code describing the condition. [Error codes are currently meaningless integers. In the future, real values will be specified.] If this happens, error-handler is called outside the scope of the new root – it is called in the same dynamic context in which
call-with-new-threadwas evaluated, but not in the caller's thread.All the evaluation rules for dynamic roots apply to threads.
Return
#tiff there is only one thread presently in the run queue. If Guile configuration does not include USE_COOP_THREADS (see Install Config), this always returns#t.
Suspend execution of the calling thread until the target thread terminates, unless the target thread has already terminated.
If one or more threads are waiting to execute, force an immediate context switch to one of them. Otherwise, do nothing.
Lock mutex. If the mutex is already locked, the calling thread blocks until the mutex becomes available. The function returns when the calling thread owns the lock on mutex.
Unlock mutex if the calling thread owns the lock on it. Calling
unlock-mutexon a mutex not owned by the current thread results in undefined behaviour. Once a mutex has been unlocked, one thread blocked on mutex is awakened and grabs the mutex lock.
Wait for condition variable c, locking mutex m when it becomes available. Caller needs to unlock m afterwards.
Signal condition variable c. If more than one thread is waiting for c (with
wait-condition-variable), only one of them receives the signal.
Note that signal-condition-variable does not unlock the mutex,
so you may need to do something like:
(define (do-something c m)
(wait-condition-variable c)
;; do something
(unlock-mutex m)
(signal-condition-variable c))