call_once coordinates one-time initialization across threads. A once_flag object records whether its callback has run; concurrent callers using that flag wait until initialization finishes, then continue with the initialized object. section 20.2 section 21.2
Initialize a shared error log
Declare an initially unused stream, a once_flag initialized with ONCE_FLAG_INIT, and an initialization callback. Before every use, call call_once(&errlog_flag, errlog_fopen); the callback can seed randomness, construct a filename, open the stream, and enable line buffering. After call_once returns, the caller can use errlog, while other threads are synchronized with the same completed initialization. section 20.2 section 21.2
void call_once(once_flag* flag, void cb(void));
Use the compact declaration to see the flag-and-callback interface: void call_once(once_flag* flag, void cb(void)); section 20.2
The first call with a given flag is special: it executes the callback and acts as a release operation. Later calls acquire that flag, making the callback's writes visible to their threads. Prefer compile-time or main-thread initialization when possible; call_once serves dynamic initialization that cannot be arranged before concurrency begins. section 20.8 section 21.2
TAKEAWAY: Pair every access to a lazily initialized shared object with the same once_flag and initialization callback, and use the object only after call_once returns. section 20.2


