Thread-Safe Initialization
What problem does std::call_once solve?
std::once_flag flag;
std::shared_ptr<Resource> resource;
void init() {
std::call_once(flag, []() {
resource = std::make_shared<Resource>();
});
}
Sign in to answer questions and track your progress
Sign In