Namespaces
Variants

std:: once_flag

From cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
(C++11)
(C++11)
once_flag
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
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
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
定义于头文件 <mutex>
class once_flag ;
(C++11 起)

std::once_flag 是用于 std::call_once 的辅助结构体。

一个类型为 std::once_flag 的对象被传递给多个对 std::call_once 的调用时,可使这些调用相互协调,从而保证其中只有一个调用能够实际运行至完成。

std::once_flag 既不可复制也不可移动。

目录

成员函数

std::once_flag:: once_flag

constexpr once_flag ( ) noexcept ;

构造一个 once_flag 对象。内部状态被设置为指示尚未调用任何函数。

参数

(无)


参见

(C++11)
即使被多个线程调用也仅执行函数一次
(函数模板)
C 文档 for once_flag