Concurrent access occurs when multiple threads use the same data during overlapping execution. A thread-safe data structure preserves its invariants and avoids lost or corrupted data, but safety alone does not guarantee that threads can work on the data at the same time: a mutex can serialize access by making threads take turns. section 6.1
Designing for concurrent access means considering both safety and the opportunity for threads to proceed concurrently:
- Preserve invariants, avoid races in the interface by providing complete operations, consider exception behavior, and restrict lock scope to reduce deadlock risks. section 6.1.1
- Ask which operations may overlap, whether locks can cover smaller regions, and whether different parts of the data structure can use different mutexes. section 6.1.1
Shared data and data structures
Sharing an apartment’s kitchen or bathroom illustrates how shared resources need rules for access. In C++, stacks, queues, hash maps, and linked lists can be designed with locks to protect data; the design determines where access must take turns and where threads may overlap. section 3.0 section 6.4
