Answers

Solutions[edit | edit source]

Listed here are programs that are solutions to the exercises posed in the other tutorial documents. You can compare your solution to them and also use them if you get stuck.

You'll find the programs in https://github.com/graeme-a-stewart/cpp-concurrency, under src/cpp11 for 01-03 and src/tbb for 04-07.

01 Basic Thread Management[edit | edit source]

  1. start-threads.cc
    1. start-threads.cc (manual) and start-threads-vec.cc (using std::vector)
  2. thread-arguments.cc
  3. thread-arguments-problems-fixed.cc and thread-arguments-problems2-fixed.cc
  4. hw-concurrency.cc

02 Mutexes and Atomics[edit | edit source]

  1. thread-arguments-mutex.cc
  2. multithread-sum-fixed-atomic.cc and multithread-sum-fixed-mutex.cc.
  3. See multithread-sum-fixed-atomic-efficient.cc and multithread-sum-fixed-mutex-efficient.cc and compare with the versions above.
  4. deadlock-fixed.cc and deadlock-fixed-using-lock-adoption.cc

03 Async and Futures[edit | edit source]

  1. async-tasks.cc
  2. async-tasks-multi.cc

04 TBB Loops[edit | edit source]

  1. parallel-for-basic.cc
  2. parallel-for-lambda.cc
  3. parallel-reduce.cc
  4. parallel-mandel.cc (see parallel-mandel-vector.cc for the same donw with std::vector storage)

05 TBB Containers[edit | edit source]

  1. concurrent-vector.cc and concurrent-vector-stdthread.cc (see also concurrent-vector-grow-by.cc)
  2. generate-and-filter.cc

06 TBB Pipelines[edit | edit source]

  1. maths-pipeline.cc

07 TBB Graphs[edit | edit source]

N.B. These examples are in the graph subdirectory

  1. data-flow.cc and data-flow-ptr.cc (which uses shared_ptr).
    • See dep-graph.cc and dep-graph-broadcast.cc for multiple data paths a la tee
  2. det-data-proc.cc.

08 TBB Tasks[edit | edit source]

N.B. These examples are in the tasks subdirectory

  1. maze.cc
  2. cancel-sleep.cc