Initialising with std::call_once() in a multithreading environment [duplicate]
问题 This question already has an answer here : Is std::call_once a blocking call? (1 answer) Closed 1 year ago . I'm reading the book C++ Concurrency in Action, 2nd Edition X . The book contains an example that uses the std::call_once() function template together with an std::once_flag object to provide some kind of lazy initialisation in thread-safe way. Here a simplified excerpt from the book: class X { public: X(const connection_details& details): connection_details_{details} {} void send_data