1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // UNSUPPORTED: libcpp-has-no-threads 11 12 #include <thread> 13 #include <condition_variable> 14 #include <mutex> 15 #include <chrono> 16 #include <iostream> 17 #include <cassert> 18 f1()19void f1() 20 { 21 std::exit(0); 22 } 23 24 struct Mutex 25 { 26 unsigned state = 0; 27 Mutex() = default; 28 ~Mutex() = default; 29 Mutex(const Mutex&) = delete; 30 Mutex& operator=(const Mutex&) = delete; 31 lockMutex32 void lock() 33 { 34 if (++state == 2) 35 throw 1; // this throw should end up calling terminate() 36 } 37 unlockMutex38 void unlock() {} 39 }; 40 41 Mutex mut; 42 std::condition_variable_any cv; 43 44 void signal_me()45signal_me() 46 { 47 std::this_thread::sleep_for(std::chrono::milliseconds(500)); 48 cv.notify_one(); 49 } 50 51 int main()52main() 53 { 54 std::set_terminate(f1); 55 try 56 { 57 std::thread(signal_me).detach(); 58 mut.lock(); 59 cv.wait(mut); 60 } 61 catch (...) {} 62 assert(false); 63 } 64