Difference between revisions of "cpp/thread/once flag"
From cppreference.com
(→Member functions: fix template) |
m (+see c) |
||
(17 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
{{cpp/title|once_flag}} | {{cpp/title|once_flag}} | ||
− | {{cpp/thread/ | + | {{cpp/thread/navbar}} |
− | {{ddcl | header=mutex | | + | {{ddcl | header=mutex | since=c++11 | |
class once_flag; | class once_flag; | ||
}} | }} | ||
− | {{ | + | The class {{tt|std::once_flag}} is a helper structure for {{lc|std::call_once}}. |
− | + | An object of type {{tt|std::once_flag}} that is passed to multiple calls to {{lc|std::call_once}} allows those calls to coordinate with each other such that only one of the calls will actually run to completion. | |
+ | |||
+ | {{tt|std::once_flag}} is neither copyable nor movable. | ||
===Member functions=== | ===Member functions=== | ||
− | {{ | + | {{member | {{small|std::once_flag::}}once_flag | |
− | {{ | + | {{ddcl | |
− | {{ | + | constexpr once_flag() noexcept; |
+ | }} | ||
+ | |||
+ | Constructs an {{tt|once_flag}} object. The internal state is set to indicate that no function has been called yet. | ||
+ | |||
+ | ===Parameters=== | ||
+ | (none) | ||
+ | |||
+ | }} | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc | cpp/thread/dsc call_once}} |
− | {{ | + | {{dsc see c | c/thread/call_once | once_flag}} |
+ | {{dsc end}} | ||
+ | |||
+ | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} |
Latest revision as of 06:55, 16 October 2021
Defined in header <mutex>
|
||
class once_flag; |
(since C++11) | |
The class std::once_flag
is a helper structure for std::call_once.
An object of type std::once_flag
that is passed to multiple calls to std::call_once allows those calls to coordinate with each other such that only one of the calls will actually run to completion.
std::once_flag
is neither copyable nor movable.
Contents |
[edit] Member functions
std::once_flag::once_flag
constexpr once_flag() noexcept; |
||
Constructs an once_flag
object. The internal state is set to indicate that no function has been called yet.
Parameters
(none)
[edit] See also
(C++11) |
invokes a function only once even if called from multiple threads (function template) |
C documentation for once_flag
|