ThreadPoolTest.cc 809 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <functional>
  2. #include <boost/threadpool.hpp>
  3. #include <gtest/gtest.h>
  4. #include <glog/logging.h>
  5. #include <gflags/gflags.h>
  6. namespace Egametang {
  7. class ThreadPoolTest: public testing::Test
  8. {
  9. };
  10. static void Max(int a, int b, int* z)
  11. {
  12. *z = a > b? a : b;
  13. }
  14. TEST_F(ThreadPoolTest, Test1)
  15. {
  16. boost::threadpool::fifo_pool pool(10);
  17. std::vector<int> x(100, 8);
  18. std::vector<int> y(100, 9);
  19. std::vector<int> z(100, 0);
  20. for (int i = 0; i < 100; ++i)
  21. {
  22. pool.schedule(std::bind(&Max, x[i], y[i], &z[i]));
  23. }
  24. pool.wait();
  25. for (int i = 0; i < 100; ++i)
  26. {
  27. ASSERT_EQ(9, z[i]);
  28. }
  29. }
  30. } // namespace Egametang
  31. int main(int argc, char* argv[])
  32. {
  33. testing::InitGoogleTest(&argc, argv);
  34. google::InitGoogleLogging(argv[0]);
  35. google::ParseCommandLineFlags(&argc, &argv, true);
  36. return RUN_ALL_TESTS();
  37. }