Legend:
Library
Module
Module type
Parameter
Class
Class type
An awaitable atomic location.
This module provides a superset of the Stdlib Atomic API with more or less identical performance. The main difference is that a non-padded awaitable location takes an extra word of memory. Additionally a futex-like API provides the ability to await until an awaitable location is explicitly signaled to potentially have a different value.
Awaitable locations can be used to implement many kinds of synchronization and communication primitives.
signal awaitable tries to wake up one fiber awaitin on the awaitable location.
🐌 Generally speaking one should avoid calling signal too frequently, because the queue of awaiters is stored separately from the awaitable location and it takes a bit of effort to locate it. For example, calling signal every time a value is added to an empty data structure might not be optimal. In many cases it is faster to explicitly mark the potential presence of awaiters in the data structure and avoid calling signal when it is definitely known that there are no awaiters.
broadcast awaitable tries to wake up all fibers awaiting on the awaitable location.
🐌 The same advice as with signal applies to broadcast. In addition, it is typically a good idea to avoid potentially waking up large numbers of fibers as it can easily lead to the thundering herd phenomana.
await awaitable before suspends the current fiber until the awaitable is explicitly signaled and has a value other than before.
⚠️ This operation is subject to the ABA problem. An await for value other than A may not return after the awaitable is signaled while having the value B, because at a later point the awaitable has again the value A. Furthermore, by the time an await for value other than A returns, the awaitable might already again have the value A.
⚠️ Atomic operations that change the value of an awaitable do not implicitly wake up awaiters.