Marshall Clow | 28c391f | 2014-03-26 02:11:47 +0000 | [diff] [blame] | 1 | #include <thread> |
| 2 | #include <condition_variable> |
| 3 | #include <mutex> |
| 4 | #include <chrono> |
| 5 | #include <iostream> |
| 6 | #include <cassert> |
| 7 | |
| 8 | void f1() |
| 9 | { |
| 10 | std::exit(0); |
| 11 | } |
| 12 | |
| 13 | struct Mutex |
| 14 | { |
| 15 | unsigned state = 0; |
| 16 | Mutex() = default; |
| 17 | ~Mutex() = default; |
| 18 | Mutex(const Mutex&) = delete; |
| 19 | Mutex& operator=(const Mutex&) = delete; |
| 20 | |
| 21 | void lock() |
| 22 | { |
| 23 | if (++state == 2) |
| 24 | throw 1; // this throw should end up calling terminate() |
| 25 | } |
| 26 | |
| 27 | void unlock() {} |
| 28 | }; |
| 29 | |
| 30 | Mutex mut; |
| 31 | std::condition_variable_any cv; |
| 32 | |
| 33 | void |
| 34 | signal_me() |
| 35 | { |
| 36 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); |
| 37 | cv.notify_one(); |
| 38 | } |
| 39 | |
| 40 | int |
| 41 | main() |
| 42 | { |
| 43 | std::set_terminate(f1); |
| 44 | try |
| 45 | { |
| 46 | std::thread(signal_me).detach(); |
| 47 | mut.lock(); |
| 48 | cv.wait(mut); |
| 49 | } |
| 50 | catch (...) {} |
| 51 | assert(false); |
| 52 | } |