std::atomic_flag_wait, std::atomic_flag_wait_explicit
|
|
在标头
<atomic>
定义
|
||
void
atomic_flag_wait(
const
atomic_flag*
object, bool
old )
noexcept;
|
(1) | (C++20 起) |
void
atomic_flag_wait(
const
volatile
atomic_flag*
object, bool
old )
noexcept;
|
(2) | (C++20 起) |
void
atomic_flag_wait_explicit(
const
atomic_flag*
object,
bool old, std::memory_order order ) noexcept; |
(3) | (C++20 起) |
void
atomic_flag_wait_explicit(
const
volatile
atomic_flag*
object,
bool old, std::memory_order order ) noexcept; |
(4) | (C++20 起) |
进行原子等待操作。
比较 object->test(std::memory_order_seq_cst) 或 object->test(order) 与 old,如果它们逐位相等,那么阻塞到加载结果的值表示更改或者 *this 被 std::atomic_flag::notify_one() 或 std::atomic_flag::notify_all() 提醒(或线程被虚假地除阻)。
这些函数保证只有在值更改了的情况下才返回,即使底层实现虚假地除阻。
参数
object | - | 指向要检查并在其上等待的原子标志的指针 |
old | - | 要检测的原子标志象不再含有的值 |
order | - | 内存同步顺序 |
返回值
(无)
注解
更改检测的这种形式通常比简单轮询或纯自旋锁高效。
由于 ABA 问题,可能错失从 old 到另一值再回到 old 的更改,而不除阻。
示例
(C++20)
|
提醒至少一个在原子对象上的等待中阻塞的线程 ( std::atomic_flag
的公开成员函数) |
(C++20)
|
提醒所有在原子对象上的等待中阻塞的线程 ( std::atomic_flag
的公开成员函数) |
(C++20)
|
提醒一个在 atomic_flag_wait 中阻塞的线程 (函数) |
(C++20)
|
提醒所有在 atomic_flag_wait 中阻塞的线程 (函数) |