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