Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-06-04 11:50:34


Author: anthonyw
Date: 2008-06-04 11:50:34 EDT (Wed, 04 Jun 2008)
New Revision: 46121
URL: http://svn.boost.org/trac/boost/changeset/46121

Log:
Added free function swap() for threads
Text files modified:
   trunk/boost/thread/detail/thread.hpp | 5 +++++
   trunk/libs/thread/test/test_thread.cpp | 18 ++++++++++++++++++
   2 files changed, 23 insertions(+), 0 deletions(-)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2008-06-04 11:50:34 EDT (Wed, 04 Jun 2008)
@@ -311,6 +311,11 @@
         bool interruption_requested() const;
     };
 
+ inline void swap(thread& lhs,thread& rhs)
+ {
+ return lhs.swap(rhs);
+ }
+
 #ifdef BOOST_HAS_RVALUE_REFS
     inline thread&& move(thread&& t)
     {

Modified: trunk/libs/thread/test/test_thread.cpp
==============================================================================
--- trunk/libs/thread/test/test_thread.cpp (original)
+++ trunk/libs/thread/test/test_thread.cpp 2008-06-04 11:50:34 EDT (Wed, 04 Jun 2008)
@@ -1,5 +1,6 @@
 // Copyright (C) 2001-2003
 // William E. Kempf
+// Copyright (C) 2008 Anthony Williams
 //
 // Distributed under the Boost Software License, Version 1.0. (See accompanying
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -198,6 +199,22 @@
     timed_test(&do_test_timed_join, 10);
 }
 
+void test_swap()
+{
+ boost::thread t(simple_thread);
+ boost::thread t2(simple_thread);
+ boost::thread::id id1=t.get_id();
+ boost::thread::id id2=t2.get_id();
+
+ t.swap(t2);
+ BOOST_CHECK(t.get_id()==id2);
+ BOOST_CHECK(t2.get_id()==id1);
+
+ swap(t,t2);
+ BOOST_CHECK(t.get_id()==id1);
+ BOOST_CHECK(t2.get_id()==id2);
+}
+
 
 boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
 {
@@ -211,6 +228,7 @@
     test->add(BOOST_TEST_CASE(test_thread_no_interrupt_if_interrupts_disabled_at_interruption_point));
     test->add(BOOST_TEST_CASE(test_creation_through_reference_wrapper));
     test->add(BOOST_TEST_CASE(test_timed_join));
+ test->add(BOOST_TEST_CASE(test_swap));
 
     return test;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk