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// NOTE: TSAN will report this test as leaking a thread. 13// XFAIL: tsan 14 15// <thread> 16 17// class thread 18 19// ~thread(); 20 21#include <thread> 22#include <new> 23#include <cstdlib> 24#include <cassert> 25 26class G 27{ 28 int alive_; 29public: 30 static int n_alive; 31 static bool op_run; 32 33 G() : alive_(1) {++n_alive;} 34 G(const G& g) : alive_(g.alive_) {++n_alive;} 35 ~G() {alive_ = 0; --n_alive;} 36 37 void operator()() 38 { 39 assert(alive_ == 1); 40 assert(n_alive >= 1); 41 op_run = true; 42 } 43}; 44 45int G::n_alive = 0; 46bool G::op_run = false; 47 48void f1() 49{ 50 std::exit(0); 51} 52 53int main() 54{ 55 std::set_terminate(f1); 56 { 57 assert(G::n_alive == 0); 58 assert(!G::op_run); 59 G g; 60 { 61 std::thread t(g); 62 std::this_thread::sleep_for(std::chrono::milliseconds(250)); 63 } 64 } 65 assert(false); 66} 67