On this page:
call-in-main-thread
thread
thread?
channel
channel?
channel-put
channel-get
channel-try-get
thread-process-wait

4.3 Cooperative Threads🔗ℹ

The zuo/thread module is reprovided by zuo.

To use cooperative threads, create a threading context with call-in-main-thread, and perform thread operations—such as creating a new thread with thread or a channel with channelduring the body of the thunk provided to call-in-main-thread. Threads can block either on channels or on a process handle as from process. Only one thread runs at a time, where a thread switch happens only when a thread terminates or uses a (potentially) blocking operation.

procedure

(call-in-main-thread thunk)  any/c

  thunk : (-> any/c)
Creates a new threading context, calling thunk in the main thread of the context, and returning the value of thunk after all threads in the context have either completed or are blocked on a channel. An error is reported if no thread can run and the main thread is blocked on a channel.

procedure

(thread thunk)  thread?

  thunk : (-> any/c)

procedure

(thread? v)  boolean?

  v : any/c

procedure

(channel)  channel?

procedure

(channel? v)  boolean?

  v : any/c

procedure

(channel-put ch v)  channel?

  ch : channel?
  v : any/c

procedure

(channel-get ch)  any/c

  ch : channel?

procedure

(channel-try-get ch)  any/c

  ch : channel?
Analogous to thread, thread?, make-channel, channel?, channel-put, channel-get, and channel-try-get from racket, but channels are asynchronous (with an unbounded queue) instead of synchronous.

Except for thread? and channel?, these procedures can be used only in a threading context. A channel can be used only in the threading context where it was created.

Beware that attempting to use these operations outside of a threading context will not necessarily trigger an error, and may instead deliver an opaque threading request to the enclosing continuation prompt.

Changed in version 1.4: Added channel-try-get.

procedure

(thread-process-wait process ...)  handle?

  process : handle?
Like process-wait, but can only be used in a threading context, and counts as a blocking operation that can allow other threads to run.