test_2309.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #define BOOST_THREAD_PROVIDES_INTERRUPTIONS
  7. //#define BOOST_TEST_MODULE Boost.Threads: 2309
  8. //#include <boost/test/unit_test.hpp>
  9. #include <iostream>
  10. #include <boost/thread.hpp>
  11. #include <boost/detail/lightweight_test.hpp>
  12. using namespace std;
  13. boost::mutex mutex_;
  14. void perform()
  15. {
  16. try
  17. {
  18. boost::this_thread::sleep(boost::posix_time::seconds(100));
  19. }
  20. catch (boost::thread_interrupted& interrupt)
  21. {
  22. boost::unique_lock<boost::mutex> lock(mutex_);
  23. cerr << "Thread " << boost::this_thread::get_id() << " got interrupted" << endl;
  24. throw(interrupt);
  25. }
  26. catch (std::exception& e)
  27. {
  28. boost::unique_lock<boost::mutex> lock(mutex_);
  29. cerr << "Thread " << boost::this_thread::get_id() << " caught std::exception" << e.what() << endl;
  30. }
  31. catch (...)
  32. {
  33. boost::unique_lock<boost::mutex> lock(mutex_);
  34. cerr << "Thread " << boost::this_thread::get_id() << " caught something else" << endl;
  35. }
  36. }
  37. void ticket_2309_test()
  38. {
  39. try
  40. {
  41. boost::thread_group threads;
  42. for (int i = 0; i < 2; ++i)
  43. {
  44. threads.create_thread(perform);
  45. }
  46. //boost::this_thread::sleep(1);
  47. threads.interrupt_all();
  48. threads.join_all();
  49. }
  50. catch (...)
  51. {
  52. BOOST_TEST(false && "exception raised");
  53. }
  54. }
  55. int main()
  56. {
  57. ticket_2309_test();
  58. }