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