std::latch latch(10);
std::vector<std::thread> pool;
for (auto i = 0; i < 10; ++i) {
pool.push_back(std::thread([&,i]() {
// calc
auto index = "calc " + std::to_string(i) + "
";
std::cout << index;
//计数减一
latch.count_down();
auto dbg = "return " + std::to_string(i) + "
";
std::cout << dbg;
}));
}
//阻塞等待计数直到为零
latch.wait();