|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83995 - in branches/release: boost/thread libs/thread libs/thread/doc libs/thread/example
From: vicente.botet_at_[hidden]
Date: 2013-04-21 03:34:21
Author: viboes
Date: 2013-04-21 03:34:19 EDT (Sun, 21 Apr 2013)
New Revision: 83995
URL: http://svn.boost.org/trac/boost/changeset/83995
Log:
Thread fix #8451.
Properties modified:
branches/release/libs/thread/ (props changed)
Text files modified:
branches/release/boost/thread/scoped_thread.hpp | 56 ++++++++++++++++++++++++++++++++++++++++
branches/release/libs/thread/doc/changes.qbk | 4 +-
branches/release/libs/thread/doc/scoped_thread.qbk | 43 +++++++++++++++++++++++++++++-
branches/release/libs/thread/example/scoped_thread.cpp | 18 ++++++++++++
4 files changed, 117 insertions(+), 4 deletions(-)
Modified: branches/release/boost/thread/scoped_thread.hpp
==============================================================================
--- branches/release/boost/thread/scoped_thread.hpp (original)
+++ branches/release/boost/thread/scoped_thread.hpp 2013-04-21 03:34:19 EDT (Sun, 21 Apr 2013)
@@ -38,10 +38,35 @@
class strict_scoped_thread
{
thread t_;
+ struct dummy;
public:
BOOST_THREAD_NO_COPYABLE( strict_scoped_thread) /// non copyable
+ /*
+ *
+ */
+#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+ template <class F, class ...Args>
+ explicit strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(Args)... args,
+ typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0) :
+ t_(boost::forward<F>(f), boost::forward<Args>(args)...) {}
+#else
+ template <class F>
+ explicit strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f,
+ typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0) :
+ t_(boost::forward<F>(f)) {}
+ template <class F, class A1>
+ strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1) :
+ t_(boost::forward<F>(f), boost::forward<A1>(a1)) {}
+ template <class F, class A1, class A2>
+ strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2) :
+ t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2)) {}
+ template <class F, class A1, class A2, class A3>
+ strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2, BOOST_THREAD_FWD_REF(A3) a3) :
+ t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2), boost::forward<A3>(a3)) {}
+#endif
+
/**
* Constructor from the thread to own.
*
@@ -91,6 +116,7 @@
class scoped_thread
{
thread t_;
+ struct dummy;
public:
typedef thread::id id;
@@ -108,6 +134,31 @@
}
/**
+ *
+ */
+
+#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+ template <class F, class ...Args>
+ explicit scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(Args)... args,
+ typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0) :
+ t_(boost::forward<F>(f), boost::forward<Args>(args)...) {}
+#else
+ template <class F>
+ explicit scoped_thread(BOOST_THREAD_FWD_REF(F) f,
+ typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0) :
+ t_(boost::forward<F>(f)) {}
+ template <class F, class A1>
+ scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1) :
+ t_(boost::forward<F>(f), boost::forward<A1>(a1)) {}
+ template <class F, class A1, class A2>
+ scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2) :
+ t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2)) {}
+ template <class F, class A1, class A2, class A3>
+ scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2, BOOST_THREAD_FWD_REF(A3) a3) :
+ t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2), boost::forward<A3>(a3)) {}
+
+#endif
+ /**
* Constructor from the thread to own.
*
* @param t: the thread to own.
@@ -195,6 +246,11 @@
return t_.native_handle();
}
+ bool joinable() const BOOST_NOEXCEPT
+ {
+ return t_.joinable();
+ }
+
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
void interrupt()
{
Modified: branches/release/libs/thread/doc/changes.qbk
==============================================================================
--- branches/release/libs/thread/doc/changes.qbk (original)
+++ branches/release/libs/thread/doc/changes.qbk 2013-04-21 03:34:19 EDT (Sun, 21 Apr 2013)
@@ -49,8 +49,8 @@
* [@http://svn.boost.org/trac/boost/ticket/8323 #8323] boost::thread::try_join_for/try_join_until may block indefinitely due to a combination of problems in Boost.Thread and Boost.Chrono
* [@http://svn.boost.org/trac/boost/ticket/8337 #8337] The internal representation of "std::string(this->code()->message())" escapes, but is destroyed when it exits scope.
* [@http://svn.boost.org/trac/boost/ticket/8371 #8371] C++11 once_flag enabled when constexpr is not available
-
-
+* [@http://svn.boost.org/trac/boost/ticket/8443 #8443] Header file inclusion order may cause crashes
+* [@http://svn.boost.org/trac/boost/ticket/8451 #8451] Mmissing documented function 'boost::scoped_thread::joinable'
[heading Version 4.0.0 - boost 1.53]
Modified: branches/release/libs/thread/doc/scoped_thread.qbk
==============================================================================
--- branches/release/libs/thread/doc/scoped_thread.qbk (original)
+++ branches/release/libs/thread/doc/scoped_thread.qbk 2013-04-21 03:34:19 EDT (Sun, 21 Apr 2013)
@@ -105,6 +105,8 @@
strict_scoped_thread& operator=(strict_scoped_thread const&) = delete;
explicit strict_scoped_thread(thread&& t) noexcept;
+ template <typename F&&, typename ...Args>
+ explicit strict_scoped_thread(F&&, Args&&...);
~strict_scoped_thread();
@@ -125,7 +127,7 @@
boost::strict_scoped_thread<> t((boost::thread(F)));
-[section:default_constructor Default Constructor]
+[section:default_constructor Constructor from a __thread]
explicit strict_scoped_thread(thread&& t) noexcept;
@@ -139,6 +141,24 @@
[endsect]
+
+[section:call_constructor Move Constructor from a Callable]
+
+ template <typename F&&, typename ...Args>
+ explicit strict_scoped_thread(F&&, Args&&...);
+
+[variablelist
+
+[[Effects:] [Construct a internal thread in place.]]
+
+[[Postconditions:] [`*this.t_` refers to the newly created thread of execution and `this->get_id()!=thread::id()`.]]
+
+[[Throws:] [Any exception the thread construction can throw.]]
+
+]
+
+[endsect]
+
[section:destructor Destructor]
~strict_scoped_thread();
@@ -149,7 +169,6 @@
[[Throws:] [Nothing: The `CallableThread()(t_)` should not throw when joining the thread as the scoped variable is on a scope outside the thread function.]]
-
]
[endsect]
@@ -160,6 +179,7 @@
#include <boost/thread/scoped_thread.hpp>
+ template <class CallableThread>
class scoped_thread
{
thread t_; // for exposition purposes only
@@ -169,6 +189,8 @@
scoped_thread& operator=(const scoped_thread&) = delete;
explicit scoped_thread(thread&& th) noexcept;
+ template <typename F&&, typename ...Args>
+ explicit strict_scoped_thread(F&&, Args&&...);
~scoped_thread();
@@ -298,6 +320,23 @@
[endsect]
+[section:call_constructor Move Constructor from a Callable]
+
+ template <typename F&&, typename ...Args>
+ explicit strict_scoped_thread(F&&, Args&&...);
+
+[variablelist
+
+[[Effects:] [Construct a internal thread in place.]]
+
+[[Postconditions:] [`*this.t_` refers to the newly created thread of execution and `this->get_id()!=thread::id()`.]]
+
+[[Throws:] [Any exception the thread construction can throw.]]
+
+]
+
+[endsect]
+
[section:destructor Destructor]
Modified: branches/release/libs/thread/example/scoped_thread.cpp
==============================================================================
--- branches/release/libs/thread/example/scoped_thread.cpp (original)
+++ branches/release/libs/thread/example/scoped_thread.cpp 2013-04-21 03:34:19 EDT (Sun, 21 Apr 2013)
@@ -64,6 +64,24 @@
// do_something_in_current_thread();
// do_something_with_current_thread(boost::thread(g));
// }
+ {
+ int some_local_state;
+ boost::scoped_thread<> t( (boost::thread(func(some_local_state))));
+
+ if (t.joinable())
+ t.join();
+ else
+ do_something_in_current_thread();
+ }
+ {
+ int some_local_state;
+ boost::thread t(( func(some_local_state) ));
+ boost::scoped_thread<> g( (boost::move(t)) );
+ t.detach();
+
+ do_something_in_current_thread();
+ }
+
return 0;
}
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