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