ThreadPoolTest.cc 673 B

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