[#absl-call_once] = xref:absl.adoc[absl]::call_once :relfileprefix: ../ :mrdocs: For all invocations using a given `once_flag`, invokes a given `fn` exactly once across all threads. The first call to `call_once()` with a particular `once_flag` argument (that does not throw an exception) will run the specified function with the provided `args`; other calls with the same `once_flag` argument will not run the function, but will wait for the provided function to finish running (if it is still running). == Synopsis Declared in `<absl/base/call_once.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename Callable, typename... Args> void call_once( xref:absl/once_flag.adoc[absl::once_flag]& flag, Callable&& fn, Args&&... args); ---- == Description This mechanism provides a safe, simple, and fast mechanism for one‐time initialization in a multi‐threaded process. Example: class MyInitClass { public: ... mutable absl::once_flag once_; MyInitClass* init() const { absl::call_once(once_, &MyInitClass::Init, this); return ptr_; } == Parameters [cols="1,4"] |=== | Name| Description | *flag* | The `once_flag` used to distinguish this call from others. | *fn* | The callable to invoke at most once. | *args* | The arguments to pass to `fn`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#