Easy
Concurrent first use of a Meyer's singleton
Ten threads all call Counter::instance() concurrently, with no external locking, and none of them has called it before. Compiled as C++11 or later. What is guaranteed about the initialization of c?
main.cpp
class Counter {
public:
static Counter& instance() {
static Counter c; // function-local static
return c;
}
void increment() { ++n_; }
int get() const { return n_; }
private:
Counter() = default;
int n_ = 0;
};1 of 44 in Design Patterns