32_thread.cpp 385 B

12345678910111213141516171819202122232425
  1. #include <boost/thread/thread.hpp>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <iostream>
  5. #include <unistd.h>
  6. using namespace std;
  7. void threadfunc(int x)
  8. {
  9. usleep(rand() % 100000);
  10. cout << "Hello, Boost.Thread (id: " << x << ")" << endl;
  11. }
  12. int main()
  13. {
  14. srand(time(0));
  15. boost::thread t1(&threadfunc, 1);
  16. boost::thread t2(&threadfunc, 2);
  17. t1.join();
  18. t2.join();
  19. return 0;
  20. }