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