From N3220, §7.28.2.1 “The call_once
function”:
Synopsis
#include <threads.h> void call_once(once_flag *flag, void (*func)(void));
Description
The
call_once
function uses theonce_flag
pointed to by flag to ensure thatfunc
is called exactly once, the first time thecall_once
function is called with that value offlag
. Completion of an effective call to thecall_once
function synchronizes with all subsequent calls to thecall_once
function with the same value of flag.Returns
The
call_once
function returns no value.
From what it sounds like, is this supposed to be used for init()
/config()
functions that are only supposed to be called once? Or am I completely misunderstanding it and it is something pertinent to threads?
What is this useful for? What is flag
, and how is it relevant here?
func
synchronizes with all previous or subsequent calls tocall_once
with the sameflag
variable." <== What does this mean?func
". I am not very familiar with threads. :(scanf()
andprintf()
don't get closed for seeking recommendations for software tools. 2. I do not see any duplicate aboutcall_once()
.