► |  | 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 | Objective-C FFI
5.11 | Cocoa Foundation
5.12 | COM (Common Object Model)
5.13 | File Security-Guard Checks
5.14 | Windows API Helpers

On this page:

start-atomic
end-atomic
start-breakable-atomic
end-breakable-atomic
call-as-atomic
call-as-nonatomic
in-atomic-mode?

top ← prev up next →

#### 5.8`` Atomic Execution

(require ffi/unsafe/atomic) | package: base

> procedure (start-atomic) → void?
> procedure (end-atomic) → void?

Disables and enables context switches and delivery of break exceptions at the level of Racket threads. Calls to start-atomic and end-atomic can be nested.

Using call-as-atomic is somewhat safer, in that call-as-atomic correctly catches exceptions and re-raises them after exiting atomic mode. For simple uses where exceptions need not be handled, however, start-atomic and end-atomic are faster.

> procedure (start-breakable-atomic) → void?
> procedure (end-breakable-atomic) → void?

Like start-atomic and end-atomic, but the delivery of break exceptions is not suspended. To ensure that a call to start-atomic is reliably paired with a call to end-atomic, use dynamic-wind pre- and post thunks or some other context where breaks are disabled. These variants are not faster than plain start-atomic and end-atomic.

> procedure (call-as-atomic thunk) → any
> thunk : (-> any)

Calls thunk in atomic mode. If thunk raises an exception, the exception is caught and re-raised after exiting atomic mode.

When call-as-atomic is used in the dynamic extent of call-as-atomic, then thunk is simply called directly (as a non-tail call).

> procedure (call-as-nonatomic thunk) → any
> thunk : (-> any)

Within the dynamic extent of a call-as-atomic, calls thunk in non-atomic mode. Beware that the current thread may be suspended or terminated by other threads during the execution of thunk, in which case the call never returns.

When used not in the dynamic extent of call-as-atomic, call-as-nonatomic raises exn:fail:contract.

> procedure (in-atomic-mode?) → boolean?

Returns #t if Racket context switches are disabled, #f otherwise.
top ← prev up next →