test_5891.cpp 679 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (C) 2010 Vicente Botet
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #define BOOST_THREAD_VERSION 2
  6. #include <iostream>
  7. #include <boost/thread/thread_only.hpp>
  8. using namespace std;
  9. using namespace boost;
  10. struct X {
  11. void operator()()
  12. {
  13. boost::this_thread::sleep(posix_time::seconds(2));
  14. }
  15. };
  16. int main()
  17. {
  18. X run;
  19. boost::thread myThread(run);
  20. boost::this_thread::yield();
  21. if(myThread.timed_join(posix_time::seconds(5)))
  22. {
  23. cout << "thats ok";
  24. return 0;
  25. }
  26. else
  27. {
  28. cout << "too late";
  29. return 1;
  30. }
  31. }