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