Identifying concurrency issues in C++ code
This easy concurrency question tests whether you can spot a common pitfall in multi-threaded C++ programs. Rather than asking you to write thread-safe code from scratch, it presents a realistic snippet and asks you to reason about what could go wrong when multiple threads access or modify shared state.
Questions of this type are common in systems interviews at trading firms and infrastructure teams. They reward clarity of thinking about execution ordering, visibility across threads, and the guarantees (or lack thereof) that the C++ memory model provides. A good answer identifies the specific issue, explains why it matters, and sketches what would be required to fix it.
- Memory visibility and the happens-before relation
- Data races and undefined behaviour
- Synchronisation primitives and their scope
- Compiler and hardware reordering