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