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