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 // <thread>
10 
11 // class thread
12 
13 // thread(const thread&) = delete;
14 
15 #include <thread>
16 #include <new>
17 #include <cstdlib>
18 #include <cassert>
19 
20 class G
21 {
22     int alive_;
23 public:
24     static int n_alive;
25     static bool op_run;
26 
27     G() : alive_(1) {++n_alive;}
28     G(const G& g) : alive_(g.alive_) {++n_alive;}
29     ~G() {alive_ = 0; --n_alive;}
30 
31     void operator()()
32     {
33         assert(alive_ == 1);
34         assert(n_alive >= 1);
35         op_run = true;
36     }
37 
38     void operator()(int i, double j)
39     {
40         assert(alive_ == 1);
41         assert(n_alive >= 1);
42         assert(i == 5);
43         assert(j == 5.5);
44         op_run = true;
45     }
46 };
47 
48 int G::n_alive = 0;
49 bool G::op_run = false;
50 
51 int main(int, char**)
52 {
53     {
54         assert(G::n_alive == 0);
55         assert(!G::op_run);
56         std::thread t0(G(), 5, 5.5);
57         std::thread::id id = t0.get_id();
58         std::thread t1 = t0;
59         assert(t1.get_id() == id);
60         assert(t0.get_id() == std::thread::id());
61         t1.join();
62         assert(G::n_alive == 0);
63         assert(G::op_run);
64     }
65 
66   return 0;
67 }
68