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.
Declared in <absl/base/call_once.h>
class once_flag;
| Name | Description |
|---|---|
once_flag [constructor] | Constructors |
operator= [deleted] | Deleted: once_flag is not copy-assignable. |
| Name | Description |
|---|---|
call_once | 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). |