Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/thread/once flag"

From cppreference.com
< cpp‎ | thread
m (Use since= and until= params of {{ddcl}} template.)
m (+see c)
 
(5 intermediate revisions by 4 users not shown)
Line 9: Line 9:
 
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.
 
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 noncopyable.
+
{{tt|std::once_flag}} is neither copyable nor movable.
  
 
===Member functions===
 
===Member functions===
 
{{member | {{small|std::once_flag::}}once_flag |
 
{{member | {{small|std::once_flag::}}once_flag |
 
{{ddcl |
 
{{ddcl |
once_flag();
+
constexpr once_flag() noexcept;
 
}}
 
}}
  
Line 22: Line 22:
 
(none)
 
(none)
  
===Exceptions===
 
{{noexcept}}
 
 
}}
 
}}
  
Line 29: Line 27:
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc inc | cpp/thread/dsc call_once}}
 
{{dsc inc | cpp/thread/dsc call_once}}
 +
{{dsc see c | c/thread/call_once | once_flag}}
 
{{dsc end}}
 
{{dsc end}}
  
[[de:cpp/thread/once flag]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/thread/once flag]]
+
[[fr:cpp/thread/once flag]]
+
[[it:cpp/thread/once flag]]
+
[[ja:cpp/thread/once flag]]
+
[[pt:cpp/thread/once flag]]
+
[[ru:cpp/thread/once flag]]
+
[[zh:cpp/thread/once flag]]
+

Latest revision as of 06:55, 16 October 2021

 
 
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
once_flag
(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
Safe Reclamation
(C++26)
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
Free functions for atomic operations
Free functions for atomic flags
 
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) [edit]
C documentation for once_flag