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 // native_handle_type native_handle();
19 
20 #include <boost/thread/thread_only.hpp>
21 #include <cstdlib>
22 #include <boost/detail/lightweight_test.hpp>
23 
24 class G
25 {
26   int alive_;
27 public:
28   static int n_alive;
29   static bool op_run;
30 
G()31   G() :
32     alive_(1)
33   {
34     ++n_alive;
35   }
G(const G & g)36   G(const G& g) :
37     alive_(g.alive_)
38   {
39     ++n_alive;
40   }
~G()41   ~G()
42   {
43     alive_ = 0;
44     --n_alive;
45   }
46 
operator ()()47   void operator()()
48   {
49     BOOST_TEST(alive_ == 1);
50     std::cout << n_alive << std::endl;
51     //BOOST_TEST(n_alive == 1);
52     op_run = true;
53   }
54 };
55 
56 int G::n_alive = 0;
57 bool G::op_run = false;
58 
main()59 int main()
60 {
61   {
62     boost::thread t0( (G()));
63     boost::thread::id id0 = t0.get_id();
64     boost::thread t1;
65     boost::thread::id id1 = t1.get_id();
66     t0.swap(t1);
67     BOOST_TEST(t0.get_id() == id1);
68     BOOST_TEST(t1.get_id() == id0);
69     t1.join();
70     return boost::report_errors();
71   }
72 }
73 
74