Mutual exclusion¶
Category: Synchronization · Status: stub · Lessons: chapter 02, Shared state
One line: The guarantee that at most one task is inside a critical section at any moment.
Also called: exclusive access.
How it connects¶
flowchart LR
n_data_race["Data race"]
n_mutex["Mutex"]
n_mutual_exclusion["Mutual exclusion"]
n_race_condition["Race condition"]
n_synchronization["Synchronization"]
n_toctou["Time of check to time of use"]
n_mutex -->|is a| n_mutual_exclusion
n_mutual_exclusion -->|is a| n_synchronization
n_mutual_exclusion -->|prevents| n_data_race
n_mutual_exclusion -->|prevents| n_race_condition
n_mutual_exclusion -->|prevents| n_toctou
classDef center stroke-width:3px
class n_mutual_exclusion center
classDef outside stroke-dasharray: 4 3
class n_data_race,n_mutex,n_race_condition,n_synchronization,n_toctou outside
- Is a kind of: Synchronization
- Kinds: Mutex
- Helps prevent: Data race, Race condition, Time of check to time of use
- See also: Critical section, Shared memory
In each language¶
| Rust | Enforced by types: a Mutex<T> ↗ owns its data, reachable only through the guard that lock returns |
| Go | The memory model ↗: programs must serialize access to shared data, with channel operations or the sync and sync/atomic primitives |
| JavaScript | The Web Locks API ↗ lets a script in one tab or worker hold a named lock while it works |
| Erlang and Elixir | Little shared memory to exclude: all data in messages between processes is copied ↗, except refc binaries and literals |
Where to read more¶
- In the books: Concurrent Programming: Algorithms, Principles, and Foundations, Michel Raynal — ch. 1, 'The Mutual Exclusion Problem'
- In the books: The Art of Multiprocessor Programming, Maurice Herlihy, Nir Shavit — ch. 2, 'Mutual Exclusion'
- In the books: Distributed Computing, Ajay D. Kshemkalyani, Mukesh Singhal — ch. 9, 'Distributed Mutual Exclusion Algorithms'
- In the books: Mastering C++ Multithreading, Maya Posch — ch. 2, 'Multithreading Implementation on the Processor and OS' → 'Mutual exclusion implementations'
- In the books: Concurrent Programming on Windows, Joe Duffy — ch. 6, 'Data and Control Synchronization' → 'Mutual Exclusion'
- In the books: Distributed Graph Algorithms for Computer Networks, K. Erciyes — ch. 8, 'Self-Stabilization' → 'Dijkstra’s Self-Stabilizing Mutual Exclusion Algorithm'
- Notes: Mutual Exclusion ↗
- Reference: Wikipedia: Mutual exclusion ↗