1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // UNSUPPORTED: no-threads 10 11 12 // <thread> 13 14 // class thread 15 16 // ~thread(); 17 18 #include <cassert> 19 #include <cstdlib> 20 #include <exception> 21 #include <new> 22 #include <thread> 23 24 #include "make_test_thread.h" 25 #include "test_macros.h" 26 27 class G 28 { 29 int alive_; 30 public: 31 static int n_alive; 32 static bool op_run; 33 G()34 G() : alive_(1) {++n_alive;} G(const G & g)35 G(const G& g) : alive_(g.alive_) {++n_alive;} ~G()36 ~G() {alive_ = 0; --n_alive;} 37 operator ()()38 void operator()() 39 { 40 assert(alive_ == 1); 41 assert(n_alive >= 1); 42 op_run = true; 43 } 44 }; 45 46 int G::n_alive = 0; 47 bool G::op_run = false; 48 f1()49void f1() 50 { 51 std::_Exit(0); 52 } 53 main(int,char **)54int main(int, char**) 55 { 56 std::set_terminate(f1); 57 { 58 assert(G::n_alive == 0); 59 assert(!G::op_run); 60 G g; 61 { 62 std::thread t = support::make_test_thread(g); 63 std::this_thread::sleep_for(std::chrono::milliseconds(250)); 64 } 65 } 66 assert(false); 67 68 return 0; 69 } 70