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 // void swap(thread& x, thread& y);
17 
18 #include <boost/thread/thread_only.hpp>
19 #include <new>
20 #include <cstdlib>
21 #include <cassert>
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     //BOOST_TEST(n_alive == 1);
51     op_run = true;
52   }
53 };
54 
55 int G::n_alive = 0;
56 bool G::op_run = false;
57 
main()58 int main()
59 {
60   {
61     boost::thread t0( (G()));
62     boost::thread::id id0 = t0.get_id();
63     boost::thread t1;
64     boost::thread::id id1 = t1.get_id();
65     swap(t0, t1);
66     BOOST_TEST(t0.get_id() == id1);
67     BOOST_TEST(t1.get_id() == id0);
68     t1.join();
69   }
70   return boost::report_errors();
71 }
72 
73