<分区>
我是 C++ 并发编程的初学者。我阅读了有关 std::atomic_flag 的内容,但我不明白此 atomic_flag 的用处。也许有人可以向我解释 atomic_flag 对哪些任务有用
标签 c++ concurrency
<分区>
我是 C++ 并发编程的初学者。我阅读了有关 std::atomic_flag 的内容,但我不明白此 atomic_flag 的用处。也许有人可以向我解释 atomic_flag 对哪些任务有用
最佳答案
cppreference.com has a usage example .它还包含以下解释性说明:
Unlike all specializations of
std::atomic
, it is guaranteed to be lock-free.
换句话说:您可以像使用 std::atomic<bool>
一样使用它但增加了无锁保证(虽然在大多数系统上 std::atomic<bool>
也将是无锁的,即 std::atomic<bool>::is_always_lock_free
将是 true
)。
关于c++ - atomic_flag 在 C++ 上的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59194256/