► |  | The Racket Foreign Interface

1 | Overview
2 | Loading Foreign Libraries
3 | C Types
4 | Pointer Functions
5 | Derived Utilities
6 | Miscellaneous Support
7 | Unexported Primitive Functions
| Bibliography
| Index

▼ | 5 | Derived Utilities

5.1 | Safe Homogenous Vectors
5.2 | Safe C Vectors
5.3 | Tagged C Pointer Types
5.4 | Serializable C Struct Types
5.5 | Defining Bindings
5.6 | Allocation and Finalization
5.7 | Custodian Shutdown Registration
5.8 | Atomic Execution
5.9 | Speculatively Atomic Execution
5.10 | Thread Scheduling
5.11 | Ports
5.12 | Process-Wide and Place-Wide Registration
5.13 | Operating System Threads
5.14 | Garbage Collection Callbacks
5.15 | Objective-C FFI
5.16 | Cocoa Foundation
5.17 | COM (Common Object Model)
5.18 | File Security-Guard Checks
5.19 | Windows API Helpers

On this page:

os-thread-enabled?
call-in-os-thread
make-os-semaphore
os-semaphore-post
os-semaphore-wait

top ← prev up next →

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

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.
top ← prev up next →