5.13 Operating System Threads
(require ffi/unsafe/os-thread) | package: base |
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.
添加于package base的6.90.0.9版本。
函数
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.