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: libcpp-has-no-threads 10 11 12 // <thread> 13 14 // class thread 15 16 // ~thread(); 17 18 #include <thread> 19 #include <new> 20 #include <cstdlib> 21 #include <cassert> 22 23 #include "make_test_thread.h" 24 #include "test_macros.h" 25 26 class G 27 { 28 int alive_; 29 public: 30 static int n_alive; 31 static bool op_run; 32 G()33 G() : alive_(1) {++n_alive;} G(const G & g)34 G(const G& g) : alive_(g.alive_) {++n_alive;} ~G()35 ~G() {alive_ = 0; --n_alive;} 36 operator ()()37 void operator()() 38 { 39 assert(alive_ == 1); 40 assert(n_alive >= 1); 41 op_run = true; 42 } 43 }; 44 45 int G::n_alive = 0; 46 bool G::op_run = false; 47 f1()48void f1() 49 { 50 std::_Exit(0); 51 } 52 main(int,char **)53int main(int, char**) 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 = support::make_test_thread(g); 62 std::this_thread::sleep_for(std::chrono::milliseconds(250)); 63 } 64 } 65 assert(false); 66 67 return 0; 68 } 69