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 // Copyright (C) 2011 Vicente J. Botet Escriba 10 // 11 // Distributed under the Boost Software License, Version 1.0. (See accompanying 12 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 13 14 // <boost/thread/thread.hpp> 15 16 // class thread 17 18 // thread(thread&& t); 19 20 #include <boost/thread/thread_only.hpp> 21 #include <new> 22 #include <cstdlib> 23 #include <boost/detail/lightweight_test.hpp> 24 25 class G 26 { 27 int alive_; 28 public: 29 static int n_alive; 30 static bool op_run; 31 G()32 G() : 33 alive_(1) 34 { 35 ++n_alive; 36 } G(const G & g)37 G(const G& g) : 38 alive_(g.alive_) 39 { 40 ++n_alive; 41 } ~G()42 ~G() 43 { 44 alive_ = 0; 45 --n_alive; 46 } 47 operator ()()48 void operator()() 49 { 50 BOOST_TEST(alive_ == 1); 51 //BOOST_TEST(n_alive == 1); 52 op_run = true; 53 } 54 operator ()(int i,double j)55 void operator()(int i, double j) 56 { 57 BOOST_TEST(alive_ == 1); 58 std::cout << __FILE__ << ":" << __LINE__ <<" " << n_alive << std::endl; 59 //BOOST_TEST(n_alive == 1); 60 BOOST_TEST(i == 5); 61 BOOST_TEST(j == 5.5); 62 op_run = true; 63 } 64 }; 65 66 int G::n_alive = 0; 67 bool G::op_run = false; 68 make_thread()69boost::thread make_thread() { 70 return boost::thread(G(), 5, 5.5); 71 } 72 main()73int main() 74 { 75 { 76 //BOOST_TEST(G::n_alive == 0); 77 BOOST_TEST(!G::op_run); 78 boost::thread t0((G())); 79 boost::thread::id id = t0.get_id(); 80 boost::thread t1((boost::move(t0))); 81 BOOST_TEST(t1.get_id() == id); 82 BOOST_TEST(t0.get_id() == boost::thread::id()); 83 t1.join(); 84 BOOST_TEST(G::op_run); 85 } 86 //BOOST_TEST(G::n_alive == 0); 87 { 88 boost::thread t1((BOOST_THREAD_MAKE_RV_REF(make_thread()))); 89 t1.join(); 90 BOOST_TEST(G::op_run); 91 } 92 //BOOST_TEST(G::n_alive == 0); 93 return boost::report_errors(); 94 } 95