C++20 中的原子操作库增加了std::atomic_wait,阻塞线程直至被提醒且原子值更改。

github上面发现一个 C++20 中 binary_semaphore、latch、barrier 的一个示例实现
https://github.com/ogiroux/atomic_wait

这个实现是在c++17的基础上完成的。

结合cppreference上面的: atomic1 、atomic_wait2、 semaphore3 、latch4、barrier5 研究比较便于理解。
atomic_wait windows上面运行
vs2019 的工程收集在: https://github.com/5455945/cpp_demo/tree/master/C%2B%2B20/atomic_wait 中。
atomic_wait


  1. atomic ↩︎

  2. atomic_wait ↩︎

  3. semaphore ↩︎

  4. latch ↩︎

  5. barrier ↩︎

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐