[lldb] Make SBProgress move-only (#124843)
[llvm-project.git] / libcxx / test / std / thread / thread.threads / thread.thread.class / thread.thread.constr / move.pass.cpp
blobb9f733c4850da55f4cef9fb0b29d0b1e80c67241
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: no-threads
11 // <thread>
13 // class thread
15 // thread(thread&& t);
17 #include <thread>
18 #include <cassert>
19 #include <cstdlib>
20 #include <utility>
22 #include "make_test_thread.h"
23 #include "test_macros.h"
25 class G
27 int alive_;
28 public:
29 static int n_alive;
30 static bool op_run;
32 G() : alive_(1) {++n_alive;}
33 G(const G& g) : alive_(g.alive_) {++n_alive;}
34 ~G() {alive_ = 0; --n_alive;}
36 void operator()()
38 assert(alive_ == 1);
39 assert(n_alive >= 1);
40 op_run = true;
44 int G::n_alive = 0;
45 bool G::op_run = false;
47 int main(int, char**)
49 assert(G::n_alive == 0);
50 assert(!G::op_run);
52 G g;
53 assert(G::n_alive == 1);
54 assert(!G::op_run);
56 std::thread t0 = support::make_test_thread(g);
57 std::thread::id id = t0.get_id();
59 std::thread t1 = std::move(t0);
60 assert(t1.get_id() == id);
61 assert(t0.get_id() == std::thread::id());
63 t1.join();
64 assert(G::n_alive == 1);
65 assert(G::op_run);
67 assert(G::n_alive == 0);
68 assert(G::op_run);
70 return 0;