gpt4 book ai didi

c++ - 异常时 call_once 的行为

转载 作者:搜寻专家 更新时间:2023-10-31 00:53:15 24 4
gpt4 key购买 nike

如果我用 call_once 调用一个函数,如果它在完成执行前抛出异常,那么 once_flag 的值是多少?

最佳答案

once_flag状态未修改,因此下一次调用 call_once与相同once_flag将调用可调用对象。

来自 [thread.once.callonce]/2 (强调)

Effects: An execution of call_­once that does not call its func is a passive execution. An execution of call_­once that calls its func is an active execution. An active execution shall call INVOKE(​std​::​forward<Callable>(func), std​::​forward<Args>(args)...). If such a call to func throws an exception the execution is exceptional, otherwise it is returning. An exceptional execution shall propagate the exception to the caller of call_­once. Among all executions of call_­once for any given once_­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.

关于c++ - 异常时 call_once 的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49356161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com