concurrency
an archive of posts with this tag
-
Concurrency bugs and debugging
Why do concurrency bugs only fire "sometimes"? What deadlocks, data races, and false sharing really are, and how to catch hard-to-reproduce bugs with ThreadSanitizer.
-
atomic and the memory model
How is sharing without locks possible? std::atomic and CAS, reordering by the compiler and CPU, and the seq_cst, acquire/release, and relaxed memory orderings with happens-before.
-
Handling results with future, promise, and async
How do you get back the one result a thread computed? future/promise, which strips away the mutex+cv plumbing, std::async, packaged_task, and exception propagation across thread boundaries.
-
condition_variable and synchronisation patterns
How do you put a thread to sleep until a condition holds, and then wake it? The condition_variable that removes busy waiting, why lost and spurious wakeups are prevented, and the producer-consumer work queue.
-
Mutexes and RAII-based locking
Why does data break when several threads touch it at once? The mutex that prevents race conditions, exception-safe RAII locking (lock_guard and unique_lock), and shared_mutex, which distinguishes reads from writes.
-
Creating and managing threads
What does it mean to run several flows of execution? Creating threads with std::thread, managing their lifetime with join/detach, and C++20 jthread with its automatic join and cooperative cancellation.