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