On this page:
os-thread-enabled?
call-in-os-thread
make-os-semaphore
os-semaphore-post
os-semaphore-wait

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 6.90.0.9 of package base.

procedure

(os-thread-enabled?)  boolean?

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

procedure

(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.

procedure

(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.

procedure

(os-semaphore-post sema)  void?

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

procedure

(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.