What this C++ concurrency question tests
This is an easy concurrency question that probes fundamental understanding of thread synchronization and mutual exclusion in C++. It asks you to reason about the observable behavior of a multi-threaded program—specifically, what gets printed and in what order.
To solve it, you need to understand how locks (mutexes) work, what sections of code run under protection, and how the scheduler might interleave execution across threads. The title hints at a lock being held; the question rewards careful reading of which operations are guarded and which are not. This type of reasoning is essential for writing correct concurrent code in low-latency systems.
- Mutex and lock semantics
- Critical sections and mutual exclusion
- Thread interleaving and race conditions
- Output buffering and flush behavior