Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53385 - in trunk: boost/thread boost/thread/detail libs/thread/test
From: anthony_at_[hidden]
Date: 2009-05-29 05:57:16


Author: anthonyw
Date: 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
New Revision: 53385
URL: http://svn.boost.org/trac/boost/changeset/53385

Log:
Attempts to improve the boost::thread move semantics; separated tests to give clearer ID; incorporated patch to fix issue #2062
Added:
   trunk/libs/thread/test/test_thread_move_return.cpp (contents, props changed)
   trunk/libs/thread/test/test_thread_return_local.cpp (contents, props changed)
Text files modified:
   trunk/boost/thread/detail/move.hpp | 4 ++--
   trunk/boost/thread/detail/thread.hpp | 18 ++++++++++++++----
   trunk/boost/thread/locks.hpp | 11 +++++++++++
   trunk/libs/thread/test/Jamfile.v2 | 2 ++
   trunk/libs/thread/test/test_thread_move.cpp | 18 +-----------------
   5 files changed, 30 insertions(+), 23 deletions(-)

Modified: trunk/boost/thread/detail/move.hpp
==============================================================================
--- trunk/boost/thread/detail/move.hpp (original)
+++ trunk/boost/thread/detail/move.hpp 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
@@ -41,9 +41,9 @@
 
 #ifndef BOOST_NO_SFINAE
     template<typename T>
- typename enable_if<boost::is_convertible<T&,detail::thread_move_t<T> >, T >::type move(T& t)
+ typename enable_if<boost::is_convertible<T&,detail::thread_move_t<T> >, detail::thread_move_t<T> >::type move(T& t)
     {
- return T(detail::thread_move_t<T>(t));
+ return detail::thread_move_t<T>(t);
     }
 #endif
     

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
@@ -144,6 +144,9 @@
         struct dummy;
 #endif
     public:
+#ifdef __SUNPRO_CC
+ thread(const volatile thread&);
+#endif
         thread();
         ~thread();
 
@@ -201,14 +204,21 @@
             thread_info=x->thread_info;
             x->thread_info.reset();
         }
-
+
+#ifdef __SUNPRO_CC
+ thread& operator=(thread x)
+ {
+ swap(x);
+ return *this;
+ }
+#else
         thread& operator=(detail::thread_move_t<thread> x)
         {
             thread new_thread(x);
             swap(new_thread);
             return *this;
         }
-
+#endif
         operator detail::thread_move_t<thread>()
         {
             return move();
@@ -339,9 +349,9 @@
         return t;
     }
 #else
- inline thread move(detail::thread_move_t<thread> t)
+ inline detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)
     {
- return thread(t);
+ return t;
     }
 #endif
 

Modified: trunk/boost/thread/locks.hpp
==============================================================================
--- trunk/boost/thread/locks.hpp (original)
+++ trunk/boost/thread/locks.hpp 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
@@ -214,6 +214,9 @@
         unique_lock& operator=(unique_lock&);
         unique_lock& operator=(upgrade_lock<Mutex>& other);
     public:
+#ifdef __SUNPRO_CC
+ unique_lock(const volatile unique_lock&);
+#endif
         unique_lock():
             m(0),is_locked(false)
         {}
@@ -297,12 +300,20 @@
             return detail::thread_move_t<unique_lock<Mutex> >(*this);
         }
 
+#ifdef __SUNPRO_CC
+ unique_lock& operator=(unique_lock<Mutex> other)
+ {
+ swap(other);
+ return *this;
+ }
+#else
         unique_lock& operator=(detail::thread_move_t<unique_lock<Mutex> > other)
         {
             unique_lock temp(other);
             swap(temp);
             return *this;
         }
+#endif
 
         unique_lock& operator=(detail::thread_move_t<upgrade_lock<Mutex> > other)
         {

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
@@ -38,6 +38,8 @@
           [ thread-run test_thread_id.cpp ]
           [ thread-run test_hardware_concurrency.cpp ]
           [ thread-run test_thread_move.cpp ]
+ [ thread-run test_thread_return_local.cpp ]
+ [ thread-run test_thread_move_return.cpp ]
           [ thread-run test_thread_launching.cpp ]
           [ thread-run test_thread_mf.cpp ]
           [ thread-run test_move_function.cpp ]

Modified: trunk/libs/thread/test/test_thread_move.cpp
==============================================================================
--- trunk/libs/thread/test/test_thread_move.cpp (original)
+++ trunk/libs/thread/test/test_thread_move.cpp 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 Anthony Williams
+// Copyright (C) 2007-9 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)
@@ -33,21 +33,6 @@
     BOOST_CHECK_EQUAL(the_id,x_id);
 }
 
-boost::thread make_thread_return_lvalue(boost::thread::id* the_id)
-{
- boost::thread t(do_nothing,the_id);
- return boost::move(t);
-}
-
-void test_move_from_function_return_lvalue()
-{
- boost::thread::id the_id;
- boost::thread x=make_thread_return_lvalue(&the_id);
- boost::thread::id x_id=x.get_id();
- x.join();
- BOOST_CHECK_EQUAL(the_id,x_id);
-}
-
 void test_move_assign()
 {
     boost::thread::id the_id;
@@ -66,7 +51,6 @@
 
     test->add(BOOST_TEST_CASE(test_move_on_construction));
     test->add(BOOST_TEST_CASE(test_move_from_function_return));
- test->add(BOOST_TEST_CASE(test_move_from_function_return_lvalue));
     test->add(BOOST_TEST_CASE(test_move_assign));
     return test;
 }

Added: trunk/libs/thread/test/test_thread_move_return.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/test_thread_move_return.cpp 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
@@ -0,0 +1,35 @@
+// Copyright (C) 2009 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)
+#include <boost/thread/thread.hpp>
+#include <boost/test/unit_test.hpp>
+
+void do_nothing(boost::thread::id* my_id)
+{
+ *my_id=boost::this_thread::get_id();
+}
+
+boost::thread make_thread_move_return(boost::thread::id* the_id)
+{
+ boost::thread t(do_nothing,the_id);
+ return boost::move(t);
+}
+
+void test_move_from_function_move_return()
+{
+ boost::thread::id the_id;
+ boost::thread x=make_thread_return_local(&the_id);
+ boost::thread::id x_id=x.get_id();
+ x.join();
+ BOOST_CHECK_EQUAL(the_id,x_id);
+}
+
+boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
+{
+ boost::unit_test_framework::test_suite* test =
+ BOOST_TEST_SUITE("Boost.Threads: thread move test suite");
+
+ test->add(BOOST_TEST_CASE(test_move_from_function_move_return));
+ return test;
+}

Added: trunk/libs/thread/test/test_thread_return_local.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/test_thread_return_local.cpp 2009-05-29 05:57:15 EDT (Fri, 29 May 2009)
@@ -0,0 +1,35 @@
+// Copyright (C) 2009 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)
+#include <boost/thread/thread.hpp>
+#include <boost/test/unit_test.hpp>
+
+void do_nothing(boost::thread::id* my_id)
+{
+ *my_id=boost::this_thread::get_id();
+}
+
+boost::thread make_thread_return_local(boost::thread::id* the_id)
+{
+ boost::thread t(do_nothing,the_id);
+ return t;
+}
+
+void test_move_from_function_return_local()
+{
+ boost::thread::id the_id;
+ boost::thread x=make_thread_return_local(&the_id);
+ boost::thread::id x_id=x.get_id();
+ x.join();
+ BOOST_CHECK_EQUAL(the_id,x_id);
+}
+
+boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
+{
+ boost::unit_test_framework::test_suite* test =
+ BOOST_TEST_SUITE("Boost.Threads: thread move test suite");
+
+ test->add(BOOST_TEST_CASE(test_move_from_function_return_local));
+ 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