文章目录
欢迎访问个人网络日志🌹🌹知行空间🌹🌹
线程闩std::latch和线程卡std::barrier
线程闩std::latch
线程闩std::latch
是c++20
中引入的类,是为了计数std::ptrdiff_t
类型的变量。
std::latch
中使用的计数器在创建时初始化,线程工作过程中逐渐减少变量的值,直到为零。
std::latch
对象中的值不支持重置或修改。
#include <thread>
#include <latch>
#include <vector>
#include <future>
struct my_data
{
int x;
int y;
};
my_data make_data(int i){
return {
i, i+1}; }
void do_more_stuff() {
}
void process_data(my_data &data, unsigned count)
{
}
void foo(){
unsigned const thread_count=10;
std::experimental::latch done(thread_count<