nccl_gpu_common_test.cc 469 字节
Newer Older
D
Dong Zhihong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include "paddle/operators/nccl/nccl_gpu_common.h"

#include <gtest/gtest.h>

#include <chrono>
#include <thread>
#include <vector>

TEST(WaitGroup, wait) {
  WaitGroup wg;
  auto run_thread = [](int idx) {
    wg.Add(1);
    std::this_thread::sleep_for(std::chrono::seconds(1));
    wg.Done();
  };

  std::vector<std::thread> ths;
  constexpr const int TNUM = 5;
  for (int i = 0; i < TNUM; ++i) {
    ths.emplace_back(std::thread(run_thread, i));
  }
  wg.Wait();
}