Next: , Previous: , Up: Scheme reference   [Contents][Index]


4.2 Atomics

The (hoot atomics) module provides an API compatible with Guile’s (ice-9 atomic) module. Atomic operations allow for concurrent access to a resource form many threads without the need to use thread synchronization constructs like mutexes. Currently, WebAssembly assumes single-threaded execution, making atomicity trivial. See the Guile manual for more detailed information.

Procedure: make-atomic-box init

Return a new atomic box with an initial stored value of init.

Procedure: atomic-box-ref box

Return the value stored within the atomic box box.

Procedure: atomic-box-set! box val

Store val into the atomic box box.

Procedure: atomic-box-swap! box val

Store val into the atomic box box, and return the value that was previously stored in the box.

Procedure: atomic-box-compare-and-swap! box expected desired

If the value of the atomic box box is the same as expected (in the sense of eq?), replace the contents of the box with desired. Otherwise, the box is not updated. Return the previous value of the box in either case. You can know if the swap worked by checking if the return value is eq? to expected.