5.10 Speculatively Atomic Execution

► |  | 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 | Static Callout and Callback Cores
5.6 | Defining Bindings
5.7 | Allocation and Finalization
5.8 | Custodian Shutdown Registration
5.9 | Atomic Execution
5.10 | Speculatively Atomic Execution
5.11 | Thread Scheduling
5.12 | Ports
5.13 | Process-Wide and Place-Wide Registration
5.14 | Operating System Threads
5.15 | Garbage Collection Callbacks
5.16 | Objective-C FFI
5.17 | Cocoa Foundation
5.18 | COM (Common Object Model)
5.19 | File Security-Guard Checks
5.20 | Windows API Helpers
5.21 | Virtual Machine Primitives
5.22 | Declaring Foreign Libraries Needed at Run Time

On this page:

call-as-nonatomic-retry-point
try-atomic

Racket
top contents ← prev up next →

### 5.10 Speculatively Atomic Execution🔗ℹ

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

The ffi/unsafe/try-atomic library supports atomic execution that can be suspended and resumed in non-atomic mode if it takes too long or if some external event causes the attempt to be abandoned.

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

Calls thunk in atomic mode (see start-atomic and end-atomic) while allowing thunk to use try-atomic. Any incomplete computations started with try-atomic are run non-atomically after thunk returns. The result of thunk is used as the result of call-as-nonatomic-retry-point.

> > procedure
> > (try-atomic |  | thunk |  |  |  |
> > |  | default-val |  |  |  |
> > | [ | #:should-give-up? give-up-proc |  |  |  |
> > |  | #:keep-in-order? keep-in-order?]) |  | → |  | any
> thunk : (-> any)
> default-val : any/c
> give-up-proc : (-> any/c) = run-200-milliseconds
> keep-in-order? : any/c = #t

Within the dynamic extent of a call-as-nonatomic-retry-point call, attempts to run thunk in the existing atomic mode. The give-up-proc procedure is called periodically to determine whether atomic mode should be abandoned; the default give-up-proc returns true after 200 milliseconds. If atomic mode is abandoned, the computation is suspended, and default-val is returned, instead. The computation is resumed later by the enclosing call-as-nonatomic-retry-point call.

If keep-in-order? is true, then if try-atomic is called after an earlier computation was suspended for the same call-as-nonatomic-retry-point call, then thunk is immediately enqueued for completion by call-as-nonatomic-retry-point and default-val is returned.

The give-up-proc callback is polled only at points where the level of atomic-mode nesting (see start-atomic, start-breakable-atomic, and call-as-atomic) is the same as at the point of calling try-atomic.

If thunk aborts the current continuation using (default-continuation-prompt-tag), the abort is suspended the resumed by the enclosing call-as-nonatomic-retry-point. Escapes to the context of the call to thunk using any other prompt tag or continuation are blocked (using dynamic-wind) and simply return (void) from thunk.

top contents ← prev up next →