|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77845 - in trunk: boost/thread boost/thread/detail libs/thread/build libs/thread/doc libs/thread/test
From: vicente.botet_at_[hidden]
Date: 2012-04-08 19:51:08
Author: viboes
Date: 2012-04-08 19:51:07 EDT (Sun, 08 Apr 2012)
New Revision: 77845
URL: http://svn.boost.org/trac/boost/changeset/77845
Log:
Thread: Added packaged_task ctor allocator + result_type + Fix issue signaled on the ML with task_object(task_object const&) in presence of task_object(task_object &&)
Text files modified:
trunk/boost/thread/detail/config.hpp | 4
trunk/boost/thread/future.hpp | 168 ++++++++++++++++++++++++++++++++-------
trunk/libs/thread/build/Jamfile.v2 | 26 ++++++
trunk/libs/thread/doc/changes.qbk | 8 +
trunk/libs/thread/doc/future_ref.qbk | 40 ++++++--
trunk/libs/thread/test/Jamfile.v2 | 44 ++++++++--
6 files changed, 237 insertions(+), 53 deletions(-)
Modified: trunk/boost/thread/detail/config.hpp
==============================================================================
--- trunk/boost/thread/detail/config.hpp (original)
+++ trunk/boost/thread/detail/config.hpp 2012-04-08 19:51:07 EDT (Sun, 08 Apr 2012)
@@ -26,6 +26,10 @@
#define BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
#endif
+#if ! defined BOOST_THREAD_DONT_PROVIDE_BASIC_THREAD_ID
+#define BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
+#endif
+
// Default version is 1
#if !defined BOOST_THREAD_VERSION
#define BOOST_THREAD_VERSION 1
Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp (original)
+++ trunk/boost/thread/future.hpp 2012-04-08 19:51:07 EDT (Sun, 08 Apr 2012)
@@ -560,17 +560,17 @@
future_object& operator=(future_object const&);
};
- template<typename T, typename Allocator>
- struct future_object_alloc: public future_object<T>
- {
- typedef future_object<T> base;
- Allocator alloc_;
-
- public:
- explicit future_object_alloc(const Allocator& a)
- : alloc_(a) {}
-
- };
+// template<typename T, typename Allocator>
+// struct future_object_alloc: public future_object<T>
+// {
+// typedef future_object<T> base;
+// Allocator alloc_;
+//
+// public:
+// explicit future_object_alloc(const Allocator& a)
+// : alloc_(a) {}
+//
+// };
class future_waiter
{
struct registered_waiter;
@@ -1274,7 +1274,7 @@
public:
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
template <class Allocator>
- explicit promise(boost::allocator_arg_t, Allocator a)
+ promise(boost::allocator_arg_t, Allocator a)
{
typedef typename Allocator::template rebind<detail::future_object<R> >::other A2;
A2 a2(a);
@@ -1480,7 +1480,7 @@
public:
#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
template <class Allocator>
- explicit promise(boost::allocator_arg_t, Allocator a)
+ promise(boost::allocator_arg_t, Allocator a)
{
typedef typename Allocator::template rebind<detail::future_object<void> >::other A2;
A2 a2(a);
@@ -1695,14 +1695,27 @@
task_base<R>
{
F f;
- task_object(F const& f_):
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ task_object(R(*f_)()):
f(f_)
{}
-#ifndef BOOST_NO_RVALUE_REFERENCES
+// task_object(const F &f_):
+// f(f_)
+// {}
task_object(F&& f_):
- f(f_)
+ f(boost::forward<F>(f_))
{}
+// task_object(task_object&& rhs):
+// f(boost::move(rhs.f_))
+// {}
#else
+// task_object(R(*f_)()):
+// f(f_)
+// {}
+ task_object(F const& f_):
+ f(f_)
+ {}
+
#if defined BOOST_THREAD_USES_MOVE
task_object(boost::rv<F>& f_):
f(boost::move(f_))
@@ -1736,17 +1749,29 @@
task_base<void>
{
F f;
- task_object(F const& f_):
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ task_object(void(*f_)()):
f(f_)
{}
-#ifndef BOOST_NO_RVALUE_REFERENCES
+// task_object(const F& f_):
+// f(f_)
+// {}
task_object(F&& f_):
- f(f_)
+ f(boost::forward<F>(f_))
{}
+// task_object(task_object&& rhs):
+// f(boost::forward<F>(rhs.f_))
+// {}
#else
+// task_object(void(*f_)()):
+// f(f_)
+// {}
+ task_object(F const& f_):
+ f(f_)
+ {}
#if defined BOOST_THREAD_USES_MOVE
task_object(boost::rv<F>& f_):
- f(boost::move(f_))
+ f(boost::forward<F>(f_))
{}
#else
task_object(boost::detail::thread_move_t<F> f_):
@@ -1779,6 +1804,7 @@
template<typename R>
class packaged_task
{
+ typedef boost::shared_ptr<detail::task_base<R> > task_ptr;
boost::shared_ptr<detail::task_base<R> > task;
bool future_obtained;
@@ -1792,25 +1818,29 @@
packaged_task& operator=(packaged_task&);// = delete;
#endif // BOOST_NO_DELETED_FUNCTIONS
public:
+ typedef R result_type;
packaged_task():
future_obtained(false)
{}
// construction and destruction
+
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ explicit packaged_task(R(*f)()):
+ task(new detail::task_object<R,R(*)()>(f)),future_obtained(false)
+ {}
template <class F>
- explicit packaged_task(F const& f):
- task(new detail::task_object<R,F>(f)),future_obtained(false)
+ explicit packaged_task(F&& f):
+ task(new detail::task_object<R,F>(boost::forward<F>(f))),future_obtained(false)
{}
+#else
explicit packaged_task(R(*f)()):
task(new detail::task_object<R,R(*)()>(f)),future_obtained(false)
{}
-
-#ifndef BOOST_NO_RVALUE_REFERENCES
template <class F>
- explicit packaged_task(F&& f):
+ explicit packaged_task(F const& f):
task(new detail::task_object<R,F>(f)),future_obtained(false)
{}
-#else
#if defined BOOST_THREAD_USES_MOVE
template <class F>
explicit packaged_task(boost::rv<F>& f):
@@ -1824,11 +1854,75 @@
#endif
#endif
-// template <class F, class Allocator>
-// explicit packaged_task(F const& f, Allocator a);
-// template <class F, class Allocator>
-// explicit packaged_task(F&& f, Allocator a);
+#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ template <class F, class Allocator>
+ packaged_task(boost::allocator_arg_t, Allocator a, F&& f)
+ {
+ typedef typename Allocator::template rebind<detail::task_object<R,F> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
+
+ task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,F>(boost::forward<F>(f)), D(a2, 1) );
+ future_obtained = false;
+ }
+// template <class F, class Allocator>
+// packaged_task(boost::allocator_arg_t, Allocator a, const F& f)
+// {
+// typedef typename Allocator::template rebind<detail::task_object<R,F> >::other A2;
+// A2 a2(a);
+// typedef thread_detail::allocator_destructor<A2> D;
+//
+// task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,F>(f), D(a2, 1) );
+// std::cout << __FILE__ ":"<<__LINE__<<std::endl;
+// future_obtained = false;
+// }
+#else
+#if defined BOOST_THREAD_USES_MOVE
+ template <class F, class Allocator>
+ packaged_task(boost::allocator_arg_t, Allocator a, boost::rv<F>& f)
+ {
+ typedef typename Allocator::template rebind<detail::task_object<R,F> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
+
+ task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,F>(boost::move(f)), D(a2, 1) );
+ future_obtained = false;
+ }
+ template <class F, class Allocator>
+ packaged_task(boost::allocator_arg_t, Allocator a, F const& f)
+ {
+ typedef typename Allocator::template rebind<detail::task_object<R,F> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
+
+ task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,F>(f), D(a2, 1) );
+ future_obtained = false;
+ }
+#else
+ template <class F, class Allocator>
+ packaged_task(boost::allocator_arg_t, Allocator a, boost::detail::thread_move_t<F> f)
+ {
+ typedef typename Allocator::template rebind<detail::task_object<R,F> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
+
+ task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,F>(boost::forward<F>(f)), D(a2, 1) );
+ future_obtained = false;
+ }
+ template <class F, class Allocator>
+ packaged_task(boost::allocator_arg_t, Allocator a, F const& f)
+ {
+ typedef typename Allocator::template rebind<detail::task_object<R,F> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
+ task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,F>(f), D(a2, 1) );
+ future_obtained = false;
+ }
+#endif // BOOST_THREAD_USES_MOVE
+#endif //BOOST_NO_RVALUE_REFERENCES
+#endif // BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
~packaged_task()
{
@@ -1906,6 +2000,14 @@
#endif
#endif
+// void reset()
+// {
+// if (!valid())
+// throw future_error(system::make_error_code(future_errc::no_state));
+// task = new detail::task_object<R,F>(task.get());
+// future_obtained=false;
+// }
+
void swap(packaged_task& other) BOOST_NOEXCEPT
{
task.swap(other.task);
@@ -1955,6 +2057,12 @@
};
+#if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
+ template <class R, class Alloc>
+ struct uses_allocator<packaged_task<R>, Alloc>
+ : public true_type {};
+#endif
+
#ifdef BOOST_NO_RVALUE_REFERENCES
#if ! defined BOOST_THREAD_USES_MOVE
template <typename T>
Modified: trunk/libs/thread/build/Jamfile.v2
==============================================================================
--- trunk/libs/thread/build/Jamfile.v2 (original)
+++ trunk/libs/thread/build/Jamfile.v2 2012-04-08 19:51:07 EDT (Sun, 08 Apr 2012)
@@ -1,6 +1,7 @@
# $Id$
# Copyright 2006-2007 Roland Schwarz.
# Copyright 2007 Anthony Williams
+# Copyright 2011-2012 Vicente J.Botet Escriba.
# 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)
@@ -46,6 +47,31 @@
<toolset>gcc:<cxxflags>-Wno-long-long
<define>BOOST_SYSTEM_NO_DEPRECATED
<library>/boost/system//boost_system
+ #-pedantic -ansi -std=gnu++0x -Wextra -fpermissive
+ <warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-pedantic
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ <toolset>darwin:<cxxflags>-Wextra
+ <toolset>darwin:<cxxflags>-pedantic
+ #<toolset>darwin:<cxxflags>-ansi
+ #<toolset>darwin:<cxxflags>-fpermissive
+ <toolset>darwin:<cxxflags>-Wno-long-long
+ #<toolset>pathscale:<cxxflags>-Wextra
+ <toolset>pathscale:<cxxflags>-Wno-long-long
+ <toolset>pathscale:<cxxflags>-pedantic
+ <toolset>clang:<cxxflags>-Wextra
+ <toolset>clang:<cxxflags>-pedantic
+ #<toolset>clang:<cxxflags>-ansi
+ #<toolset>clang:<cxxflags>-fpermissive
+ <toolset>clang:<cxxflags>-Wno-long-long
+ <toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.6.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.6.3:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.7.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.8.0:<cxxflags>-fdiagnostics-show-option
+
# : default-build <threading>multi
: usage-requirements # pass these requirement to dependents (i.e. users)
Modified: trunk/libs/thread/doc/changes.qbk
==============================================================================
--- trunk/libs/thread/doc/changes.qbk (original)
+++ trunk/libs/thread/doc/changes.qbk 2012-04-08 19:51:07 EDT (Sun, 08 Apr 2012)
@@ -28,17 +28,20 @@
* [@http://svn.boost.org/trac/boost/ticket/6272 #6272] c++11 compliance: Add thread::id hash specialization.
* [@http://svn.boost.org/trac/boost/ticket/6273 #6273] c++11 compliance: Add cv_status enum class and use it on the conditions wait functions.
* [@http://svn.boost.org/trac/boost/ticket/6231 #6231] Add BasicLockable requirements in the documentation to follow c++11.
-* [@http://svn.boost.org/trac/boost/ticket/6342 #6342] c++11 compliance: Adapt the one_flag and call_once to the c++11 interface.
+* [@http://svn.boost.org/trac/boost/ticket/6342 #6342] c++11 compliance: Adapt the one_flag to the c++11 interface.
* [@http://svn.boost.org/trac/boost/ticket/6671 #6671] upgrade_lock: missing mutex and release functions.
* [@http://svn.boost.org/trac/boost/ticket/6672 #6672] upgrade_lock:: missing constructors from time related types.
* [@http://svn.boost.org/trac/boost/ticket/6675 #6675] upgrade_lock:: missing non-member swap.
+* Added missing packaged_task::result_type and packaged_task:: constructor with allocator.
+
-
Fixed Bugs:
* [@http://svn.boost.org/trac/boost/ticket/2575 #2575] Bug- Boost 1.36.0 on Itanium platform.
+* [@http://svn.boost.org/trac/boost/ticket/4345 #4345] thread::id and joining problem with cascade of threads.
* [@http://svn.boost.org/trac/boost/ticket/4921 #4921] BOOST_THREAD_USE_DLL and BOOST_THREAD_USE_LIB are crucial and need to be documented.
* [@http://svn.boost.org/trac/boost/ticket/5013 #5013] documentation: boost::thread: pthreas_exit causes terminate().
+* [@http://svn.boost.org/trac/boost/ticket/5173 #5173] boost::this_thread::get_id is very slow.
* [@http://svn.boost.org/trac/boost/ticket/5351 #5351] interrupt a future get boost::unknown_exception.
* [@http://svn.boost.org/trac/boost/ticket/5516 #5516] Upgrade lock is not acquired when previous upgrade lock releases if another read lock is present.
* [@http://svn.boost.org/trac/boost/ticket/5990 #5990] shared_future<T>::get() has wrong return type.
@@ -46,6 +49,7 @@
* [@http://svn.boost.org/trac/boost/ticket/6222 #6222] Compile error with SunStudio: unique_future move.
* [@http://svn.boost.org/trac/boost/ticket/6673 #6673] shared_lock: move assign doesn't works with c++11.
* [@http://svn.boost.org/trac/boost/ticket/6674 #6674] shared_mutex: try_lock_upgrade_until doesn't works.
+* Fix issue signaled on the ML with task_object(task_object const&) in presence of task_object(task_object &&)
[/
Deprecated features since boost 1.50 available only until boost 1.55:
Modified: trunk/libs/thread/doc/future_ref.qbk
==============================================================================
--- trunk/libs/thread/doc/future_ref.qbk (original)
+++ trunk/libs/thread/doc/future_ref.qbk 2012-04-08 19:51:07 EDT (Sun, 08 Apr 2012)
@@ -714,7 +714,7 @@
promise();
template <class Allocator>
- explicit promise(allocator_arg_t, Allocator a);
+ promise(allocator_arg_t, Allocator a);
promise & operator=(const promise & rhs);// = delete;
promise(const promise & rhs);// = delete;
~promise();
@@ -758,7 +758,7 @@
[section:alloc_constructor Allocator Constructor]
template <class Allocator>
- explicit promise(allocator_arg_t, Allocator a);
+ promise(allocator_arg_t, Allocator a);
[variablelist
@@ -913,22 +913,21 @@
class packaged_task
{
public:
+ typedef R result_type;
+
packaged_task(packaged_task&);// = delete;
packaged_task& operator=(packaged_task&);// = delete;
// construction and destruction
packaged_task() noexcept;
- template <class F>
- explicit packaged_task(F const& f);
-
explicit packaged_task(R(*f)());
template <class F>
explicit packaged_task(F&& f);
- // template <class F, class Allocator>
- // explicit packaged_task(allocator_arg_t, Allocator a, F&& f); // NOT YET IMPLEMENTED
+ template <class F, class Allocator>
+ packaged_task(allocator_arg_t, Allocator a, F&& f);
~packaged_task()
{}
@@ -955,9 +954,6 @@
[section:task_constructor Task Constructor]
- template<typename F>
- packaged_task(F const &f);
-
packaged_task(R(*f)());
template<typename F>
@@ -968,11 +964,32 @@
[[Preconditions:] [`f()` is a valid expression with a return type convertible to `R`. Invoking a copy of `f` shall behave the same
as invoking `f`.]]
-[[Effects:] [Constructs a new __packaged_task__ with a copy of `f` stored as the associated task.]]
+[[Effects:] [Constructs a new __packaged_task__ with `boost::forward<F>(f)` stored as the associated task.]]
+
+[[Throws:] [Any exceptions thrown by the copy (or move) constructor of `f`. `std::bad_alloc` if memory for the internal data
+structures could not be allocated.]]
+
+]
+
+[endsect]
+
+[section:alloc_constructor Allocator Constructor]
+
+ template <class F, class Allocator>
+ packaged_task(allocator_arg_t, Allocator a, F&& f);
+
+[variablelist
+
+[[Preconditions:] [`f()` is a valid expression with a return type convertible to `R`. Invoking a copy of `f` shall behave the same
+as invoking `f`.]]
+
+[[Effects:] [Constructs a new __packaged_task with `boost::forward<F>(f)` stored as the associated task using the allocator `a`.]]
[[Throws:] [Any exceptions thrown by the copy (or move) constructor of `f`. `std::bad_alloc` if memory for the internal data
structures could not be allocated.]]
+[[Notes:] [Available only if BOOST_THREAD_FUTURE_USES_ALLOCATORS is defined.]]
+
]
[endsect]
@@ -994,6 +1011,7 @@
[endsect]
+
[section:move_assignment Move Assignment Operator]
packaged_task& operator=(packaged_task && other);
Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2012-04-08 19:51:07 EDT (Sun, 08 Apr 2012)
@@ -1,5 +1,6 @@
# (C) Copyright William E. Kempf 2001.
# (C) Copyright 2007 Anthony Williams.
+# (C) Copyright 2011-2012 Vicente J.Botet Escriba.
# 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)
#
@@ -21,6 +22,25 @@
project
: requirements
<threading>multi
+ <warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-pedantic
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ <toolset>darwin:<cxxflags>-Wextra
+ <toolset>darwin:<cxxflags>-pedantic
+ <toolset>darwin:<cxxflags>-Wno-long-long
+ #<toolset>pathscale:<cxxflags>-Wextra
+ <toolset>pathscale:<cxxflags>-Wno-long-long
+ <toolset>pathscale:<cxxflags>-pedantic
+ <toolset>clang:<cxxflags>-Wextra
+ <toolset>clang:<cxxflags>-pedantic
+ <toolset>clang:<cxxflags>-Wno-long-long
+ <toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.6.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.6.3:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.7.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>gcc-mingw-4.8.0:<cxxflags>-fdiagnostics-show-option
;
rule thread-run ( sources )
@@ -185,6 +205,17 @@
[ thread-run2 ./sync/futures/future/move_assign_pass.cpp : future__move_asign_p ]
[ thread-run2 ./sync/futures/future/share_pass.cpp : future__share_p ]
+ [ thread-run2 ./sync/futures/packaged_task/alloc_ctor_pass.cpp : packaged_task__alloc_ctor_p ]
+ [ thread-compile-fail-V2 ./sync/futures/packaged_task/copy_assign_fail.cpp : : packaged_task__copy_assign_f ]
+ [ thread-compile-fail-V2 ./sync/futures/packaged_task/copy_ctor_fail.cpp : : packaged_task__copy_ctor_f ]
+ [ thread-run2 ./sync/futures/packaged_task/default_ctor_pass.cpp : packaged_task__default_ctor_p ]
+ #[ thread-run2 ./sync/futures/packaged_task/dtor_pass.cpp : packaged_task__dtor_p ]
+ [ thread-run2 ./sync/futures/packaged_task/get_future_pass.cpp : packaged_task__get_future_p ]
+ [ thread-run2 ./sync/futures/packaged_task/move_ctor_pass.cpp : packaged_task__move_ctor_p ]
+ [ thread-run2 ./sync/futures/packaged_task/move_assign_pass.cpp : packaged_task__move_asign_p ]
+ [ thread-run2 ./sync/futures/packaged_task/use_allocator_pass.cpp : packaged_task__use_allocator_p ]
+ [ thread-run2 ./sync/futures/packaged_task/types_pass.cpp : futures__types_p ]
+
;
@@ -358,9 +389,9 @@
test-suite examples
:
[ thread-run ../example/monitor.cpp ]
- #[ thread-run ../example/starvephil.cpp ]
- #[ thread-run ../example/tennis.cpp ]
- #[ thread-run ../example/condition.cpp ]
+ [ compile ../example/starvephil.cpp ]
+ #[ compile ../example/tennis.cpp ]
+ [ compile ../example/condition.cpp ]
[ thread-run ../example/mutex.cpp ]
[ thread-run ../example/once.cpp ]
[ thread-run ../example/recursive_mutex.cpp ]
@@ -406,11 +437,4 @@
[ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp : reverse_lock__types_p ]
;
- explicit tt ;
- test-suite tt
- :
- #[ thread-test test_thread.cpp ]
- [ thread-run2 test_ml.cpp : test_ml ]
- ;
-
}
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