From Cppreference
|
|
|
|
|
template< class Function, class... Args> void call_once( std::once_flag& flag, Function&& f, Args&& args...);
|
|
(C++11 feature)
|
|
|
Executes the function f exactly once, even if called from several threads.
Each group of call_once invocations, which receives the same std::once_flag object, follows the following requirements:
- Exactly one execution of exactly one of the functions, passed as f to the invocations in the group, is performed. It is undefined which function will be selected for execution. The selected function runs in the same thread as call_once invocation it was passed to.
- No invocation in the group returns before the abovementioned execution of the selected function is completed successfully, that is doesn't exit via an exception.
- If the selected function exits via exception, it is propagated to the caller. Another function is selected and executed.
[edit] Parameters
flag
|
-
|
an object, for which exactly one function gets executed
|
f
|
-
|
function to call
|
args...
|
-
|
arguments to pass to the function
|
[edit] Return value
(none)
[edit] Exceptions
[edit] Example
[edit] See also
|
|
helper object to ensure that call_once invokes the function only once (class)
|