Concurrent data structures¶
Category: Lock-free · Status: stub · Lessons: chapter 02, Shared state
One line: Queues, maps, stacks and lists built to be used by many threads at once — with locks inside, lock-free algorithms, or both — so that their callers need no synchronization of their own.
Also called: concurrent collections, thread-safe containers, ConcurrentHashMap.
How it connects¶
flowchart LR
n_compare_and_swap["Compare-and-swap"]
n_concurrent_data_structures["Concurrent data structures"]
n_concurrent_data_structures -->|uses| n_compare_and_swap
classDef center stroke-width:3px
class n_concurrent_data_structures center
classDef outside stroke-dasharray: 4 3
class n_compare_and_swap outside
- Is built on: Compare-and-swap
- See also: Hazard pointers, Lock-free, Thread safety
In each language¶
| Rust | none in the standard library besides channels; crossbeam::queue ↗ has lock-free queues |
| Go | sync.Map ↗, meant for keys that are written once and read many times; a plain map needs its own mutex |
| Java | ConcurrentHashMap ↗ and the other collections in java.util.concurrent |
| Python | queue.Queue ↗, whose classes implement all the required locking |
| C# | System.Collections.Concurrent ↗: ConcurrentDictionary, ConcurrentQueue, BlockingCollection |
Where to read more¶
- In the books: C++ Concurrency in Action, Anthony Williams — ch. 6, 'Designing lock-based concurrent data structures'
- In the books: Java Concurrency in Practice, Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, Doug Lea — ch. 5, 'Building Blocks' → 'Concurrent Collections'
- In the books: The Art of Multiprocessor Programming, Maurice Herlihy, Nir Shavit — ch. 3, 'Concurrent Objects'
- In the books: Concurrency with Modern C++, Rainer Grimm — ch. 11, 'Lock-Based Data Structures'
- In the books: Concurrent Programming on Windows, Joe Duffy — ch. 12, 'Parallel Containers'
- In the books: Rust Atomics and Locks, Mara Bos — ch. 10, 'Ideas and Inspiration' → 'Lock-Free Linked List'
- Reference: Wikipedia: Concurrent data structure ↗