liveBook · Manning

Data structure

As explained in C++ Concurrency in Action, Second Edition

An organization of data that supports particular operations for storing, accessing, or modifying it.

A data structure organizes data to support particular operations. When multiple threads access one, it must either remain immutable or synchronize changes correctly. section 6.0

Designing a data structure for concurrent access involves two goals:

  • Keep operations safe: preserve invariants, provide complete operations rather than exposing steps, account for exceptions, and reduce deadlock risks. section 6.1.1
  • Allow genuine concurrency: consider whether locks can be limited to parts of an operation or different parts of the structure. section 6.1.1
  • Specify which operations may run concurrently, including whether assignment, swapping, or copying requires exclusive access. section 6.1.1

Mutexes and condition variables can support lock-based designs; atomic operations can also be used to build data structures without locks. section 6.0 section 6.4

Common concurrent structures

Stacks, queues, hash maps, and linked lists illustrate how locks can protect data and prevent data races. section 6.4

How C++ Concurrency in Action, Second Edition covers it

How deep it goes
Works through design guidelines and lock-based implementations; points to atomic, lock-free designs without detailing them here.
Examples
Uses stacks, queues, hash maps, and linked lists as lock-based concurrent structure examples.
What it assumes
Builds on mutexes and condition variables, and places lock-based design before later work with atomic operations.
What you can do after
Evaluate data structures for concurrency by identifying race risks and opportunities for parallel access.
How it connects
Connects data structures with mutexes, condition variables, atomic operations, race conditions, and deadlock.

Also explained in

Compare how 10 books explain data structure →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C++ Concurrency in Action, Second Edition. The section links point to the parts of the book it draws on.