Back to Basics: C++ Concurrency - David Olsen - CppCon 2023

Explore the basics of C++ concurrency with David Olsen at CppCon 2023, covering essential concepts such as mutexes, deadlocks, data races, and parallel algorithms.

Key takeaways
  • Understanding concurrency is important for writing correct concurrent code.
  • Concurrency is not just about using locks to protect shared resources.
  • A mutex is like a switch that controls who can enter a room; it’s a way to synchronize threads.
  • Deadlock is when at least two threads are blocked, waiting for each other to release a resource.
  • To fix a data race, you need to synchronize access to the shared resource.
  • Avoidance of data races is all about the visibility of memory changes.
  • Avoid using locks directly; use lock guards instead.
  • A scoped lock is a lock guard that locks a mutex and also releases it when it goes out of scope.
  • A container is a group of objects, such as accounts or assets, that you need to synchronize access to.
  • A parallel algorithm is one that can be executed in parallel by multiple threads.
  • Eliminating dependencies between threads can eliminate data races.
  • Use the best algorithm for your task; spending time learning about parallelism can be worth it.