absl::once_flag

Objects of this type are used to distinguish calls to call_once() and ensure the provided function is only invoked once across all threads. This type is not copyable or movable. However, it has a constexpr constructor, and is safe to use as a namespace-scoped global variable.

Synopsis

Declared in <absl/base/call_once.h>

class once_flag;

Member Functions

NameDescription
once_flag [constructor]Constructors
operator= [deleted]Deleted: once_flag is not copy-assignable.

Non-Member Functions

NameDescription
call_onceFor 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).