On this page:

5.13 Operating System Threads

The ffi/unsafe/os-thread library provides functions for running constrained Racket code in a separate thread at the operating-system level. Except for os-thread-enabled?, the functions of ffi/unsafe/os-thread are currently supported only when (system-type 'vm) returns 'chez-scheme, and even then only in certain build modes. The functions raise exn:fail:unsupported when not supported.

Added in version of package base.


(os-thread-enabled?)  boolean?

Returns #t if the other functions of ffi/unsafe/os-thread work without raising exn:fail:unsupported, #f otherwise.


(call-in-os-thread thunk)  void?

  thunk : (-> any)
Runs thunk in a separate operating-system thread, which runs concurrently to all Racket threads.

The thunk is run in atomic mode, and it must not inspect its continuation or use any Racket thread functions (such as thread or current-thread), any Racket synchronization functions (such as semaphore-post or sync), or any parameters (such as current-output-port). Variables may be safely mutated with set!, and vectors, mutable pairs, boxes, mutable structure fields, and eq?- and eqv?-based hash tables can be mutated, but the visibility of mutations to other threads is unspecified except as synchronized through os-semaphore-wait and os-semaphore-post.


(make-os-semaphore)  any

Creates a semaphore that can be used with os-semaphore-wait and os-semaphore-post to synchronize an operating-system thread with Racket threads and other operating-system threads.


(os-semaphore-post sema)  void?

  sema : any/c
Analogous to semaphore-post, but posts to a semaphore created by make-os-semaphore.


(os-semaphore-wait sema)  void?

  sema : any/c
Analogous to semaphore-wait, but waits on a semaphore created by make-os-semaphore. Waiting blocks the current thread; if the current thread is a Racket thread, then waiting also blocks all Racket threads.