Opened 12 years ago
Closed 10 years ago
#4521 closed Bugs (fixed)
Error using boost::move on packaged_task (MSVC 10)
Reported by: | ZenJu | Owned by: | viboes |
---|---|---|---|
Milestone: | Boost 1.50.0 | Component: | thread |
Version: | Boost 1.44.0 | Severity: | Showstopper |
Keywords: | move | Cc: | viboes |
Description
Hi,
the example code on futures is broken on MSVC 10 http://www.boost.org/doc/libs/1_43_0/doc/html/thread/synchronization.html#thread.synchronization.futures
int calculate_the_answer_to_life_the_universe_and_everything() { return 42; } boost::packaged_task<int> pt(calculate_the_answer_to_life_the_universe_and_everything); boost::unique_future<int> fi=pt.get_future(); boost::thread task(boost::move(pt)); // launch task on a thread
However it works if BOOST_NO_RVALUE_REFERENCES is defined. Reproducible on v1.43 and 1.44 beta1
Error:
1>shared\check_exist.cpp(16): error C2665: 'boost::move' : none of the 2 overloads could convert all the argument types 1> C:\Program Files\C++\Boost\boost/thread/detail/thread.hpp(359): could be 'boost::thread &&boost::move(boost::thread &)' 1> C:\Program Files\C++\Boost\boost/thread/detail/thread.hpp(363): or 'boost::thread &&boost::move(boost::thread &&)'
Regards, ZenJu
Change History (9)
comment:1 by , 12 years ago
Component: | None → thread |
---|---|
Milestone: | Boost 1.44.0 → To Be Determined |
Owner: | set to |
comment:2 by , 12 years ago
Cc: | added |
---|---|
Summary: | Error using boost::move on packaged_task → Error using boost::move on packaged_task (MSVC 10) |
comment:3 by , 11 years ago
comment:4 by , 11 years ago
Keywords: | move added |
---|
There is an action point to use Boost.Move. Could we consider this as a duplicate of #6194 Adapt to Boost.Move.
comment:5 by , 11 years ago
If we follows the reference documentation, the example should not works as the functor (in this case a packaged task) must be copyable.
Thread Constructor template<typename Callable> thread(Callable func); Preconditions: Callable must by copyable. Effects: func is copied into storage managed internally by the thread library, and that copy is invoked on a newly-created thread of execution. If this invocation results in an exception being propagated into the internals of the thread library that is not of type boost::thread_interrupted, then std::terminate() will be called. Postconditions: *this refers to the newly created thread of execution. Throws: boost::thread_resource_error if an error occurs. Thread Constructor with arguments template <class F,class A1,class A2,...> thread(F f,A1 a1,A2 a2,...); Preconditions: F and each An must by copyable or movable. Effects: As if thread(boost::bind(f,a1,a2,...)). Consequently, f and each an are copied into internal storage for access by the new thread. Postconditions: *this refers to the newly created thread of execution. Throws: boost::thread_resource_error if an error occurs. Note: Currently up to nine additional arguments a1 to a9 can be specified in addition to the function f.
This doesn't means that the library shouldn't provide such a feature as otherwise it is unable to work with packaged_task. I have created a feature request for this purpose #6270 c++11 compliance: Add thread constructor from movable callable and movable arguments.
comment:6 by , 11 years ago
I have tested on trunk with msvc.10 and it is working. Could you give a try on trunk?
comment:7 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 11 years ago
Milestone: | To Be Determined → Boost 1.49.0 |
---|
Committed in trunk at revision [76543].
comment:9 by , 10 years ago
Milestone: | Boost 1.49.0 → Boost 1.50.0 |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Committed in release branch at [78543]
This example also fails with GCC 4.5.4 and 4.6.1 using -std=c++0x:
There are only 2 overloads of boost::move, and these don't work for a packaged_task.
boost::move should be equivalent to std::move ifndef BOOST_NO_RVALUE_REFERENCES, shouldn't it?
Simply
works with MSVC 10 and GCC 4.5, 4.6.