Reputation: 112
If I call a function with call_once
and if it throws exception before completing execution, what will be the value of once_flag
?
Upvotes: 2
Views: 102
Reputation: 109189
once_flag
state is not modified so the next call to call_once
with the same once_flag
will invoke the callable.
From [thread.once.callonce]/2 (emphasis added)
Effects: An execution of
call_once
that does not call itsfunc
is a passive execution. An execution ofcall_once
that calls itsfunc
is an active execution. An active execution shall callINVOKE(std::forward<Callable>(func), std::forward<Args>(args)...)
. If such a call tofunc
throws an exception the execution is exceptional, otherwise it is returning. An exceptional execution shall propagate the exception to the caller ofcall_once
. Among all executions ofcall_once
for any givenonce_flag
: at most one shall be a returning execution; if there is a returning execution, it shall be the last active execution; and there are passive executions only if there is a returning execution.
Upvotes: 4