• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <thread>
11 
12 // class thread
13 
14 // ~thread();
15 
16 #include <thread>
17 #include <new>
18 #include <cstdlib>
19 #include <cassert>
20 
21 class G
22 {
23     int alive_;
24 public:
25     static int n_alive;
26     static bool op_run;
27 
G()28     G() : alive_(1) {++n_alive;}
G(const G & g)29     G(const G& g) : alive_(g.alive_) {++n_alive;}
~G()30     ~G() {alive_ = 0; --n_alive;}
31 
operator ()()32     void operator()()
33     {
34         assert(alive_ == 1);
35         assert(n_alive == 1);
36         op_run = true;
37     }
38 };
39 
40 int G::n_alive = 0;
41 bool G::op_run = false;
42 
f1()43 void f1()
44 {
45     std::exit(0);
46 }
47 
main()48 int main()
49 {
50     std::set_terminate(f1);
51     {
52         assert(G::n_alive == 0);
53         assert(!G::op_run);
54         std::thread t((G()));
55         std::this_thread::sleep_for(std::chrono::milliseconds(250));
56     }
57     assert(false);
58 }
59