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 "test_macros.h" 24 25 class G 26 { 27 int alive_; 28 public: 29 static int n_alive; 30 static bool op_run; 31 32 G() : alive_(1) {++n_alive;} 33 G(const G& g) : alive_(g.alive_) {++n_alive;} 34 ~G() {alive_ = 0; --n_alive;} 35 36 void operator()() 37 { 38 assert(alive_ == 1); 39 assert(n_alive >= 1); 40 op_run = true; 41 } 42 }; 43 44 int G::n_alive = 0; 45 bool G::op_run = false; 46 47 void f1() 48 { 49 std::_Exit(0); 50 } 51 52 int main(int, char**) 53 { 54 std::set_terminate(f1); 55 { 56 assert(G::n_alive == 0); 57 assert(!G::op_run); 58 G g; 59 { 60 std::thread t(g); 61 std::this_thread::sleep_for(std::chrono::milliseconds(250)); 62 } 63 } 64 assert(false); 65 66 return 0; 67 } 68