[#absl-call_once]
= xref:absl.adoc[absl]::call&lowbar;once
:relfileprefix: ../
:mrdocs:

For all invocations using a given `once&lowbar;flag`, invokes a given `fn` exactly once across all threads&period; The first call to `call&lowbar;once()` with a particular `once&lowbar;flag` argument (that does not throw an exception) will run the specified function with the provided `args`&semi; other calls with the same `once&lowbar;flag` argument will not run the function, but will wait for the provided function to finish running (if it is still running)&period;

== Synopsis

Declared in `&lt;absl&sol;base&sol;call&lowbar;once&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    typename Callable,
    typename&period;&period;&period; Args&gt;
void
call&lowbar;once(
    xref:absl/once_flag.adoc[absl::once&lowbar;flag]& flag,
    Callable&& fn,
    Args&&&period;&period;&period; args);
----

== Description

This mechanism provides a safe, simple, and fast mechanism for one&hyphen;time initialization in a multi&hyphen;threaded process&period;

Example&colon;

class MyInitClass &lcub; public&colon; &period;&period;&period; mutable absl&colon;&colon;once&lowbar;flag once&lowbar;&semi;

MyInitClass&ast; init() const &lcub; absl&colon;&colon;call&lowbar;once(once&lowbar;, &amp;MyInitClass&colon;&colon;Init, this)&semi; return ptr&lowbar;&semi; &rcub;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *flag*
| The `once&lowbar;flag` used to distinguish this call from others&period;
| *fn*
| The callable to invoke at most once&period;
| *args*
| The arguments to pass to `fn`&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
