Threading and work-passing patterns in C++
This medium-difficulty C++ question tests your understanding of how to correctly pass work—functions, lambdas, and callable objects—to a thread on construction. It is representative of the kinds of concurrency questions asked during implementation rounds, where precise knowledge of the standard library and common pitfalls matters.
The question challenges you to distinguish between viable and non-viable approaches by reasoning about the semantics of std::thread constructors, move semantics, type deduction, and how arguments are forwarded to the underlying callable. Common mistakes include misunderstanding how copies are made, when objects go out of scope, and which syntactic forms are even valid in the language.
- Function pointers and function objects as thread targets
- Lambda capture and thread lifetime
- Move semantics and argument forwarding in thread construction
- Decay and type deduction rules