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) + "\r\n";
            std::cout << index;

            //计数减一
            latch.count_down();
            
            auto dbg = "return " + std::to_string(i) + "\r\n";

            std::cout << dbg;

            }));
    }
    //阻塞等待计数直到为零
    latch.wait();

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2022-01-14
  • 2022-12-23
  • 2021-11-08
  • 2021-07-29
  • 2021-11-14
  • 2021-12-15
猜你喜欢
  • 2021-11-08
  • 2021-05-27
  • 2022-01-19
  • 2021-06-20
相关资源
相似解决方案