Async Mutexes
18 days ago
- #mutex
- #concurrency
- #async
- Concurrent programming over a single thread eliminates the need for mutexes, as data races are impossible with only one function executing at a time.
- Mutual exclusion is a logical property, not just a runtime one, requiring explicit annotation in the source code to ensure atomic execution segments.
- Adding `.await` in the middle of code that should be atomic can introduce logical races, highlighting the need for careful design in async programming.
- TigerBeetle uses implicit exclusion via a single-threaded model, avoiding the need for explicit mutexes in its state machine/actor style programming.
- Compaction in TigerBeetle involves concurrent disk operations and CPU-side merges, with shared state that must not be mutated concurrently by other operations.
- Explicit locking in TigerBeetle could lead to a single global lock, effectively reverting to implicit locking by acquiring it at the event loop level.
- TigerBeetle's manual callbacks and state assertions prevent unintended concurrency, contrasting with the CSP style where threads share minimal data.