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 Marshall Clow, 12 years ago

Component: Nonethread
Milestone: Boost 1.44.0To Be Determined
Owner: set to Anthony Williams

comment:2 by viboes, 12 years ago

Cc: viboes added
Summary: Error using boost::move on packaged_taskError using boost::move on packaged_task (MSVC 10)

comment:3 by Claudio Bley, 11 years ago

This example also fails with GCC 4.5.4 and 4.6.1 using -std=c++0x:

g++ -std=c++0x answer.cc -I /home/claudio/aux/include/boost-1_47/
In file included from /home/claudio/aux/include/boost-1_47/boost/thread/thread.hpp:22:0,
                 from /home/claudio/aux/include/boost-1_47/boost/thread.hpp:13,
                 from answer.cc:1:
/home/claudio/aux/include/boost-1_47/boost/thread/future.hpp: In constructor ‘boost::detail::thread_data<F>::thread_data(F&) [with F = boost::packaged_task<int>]’:
/home/claudio/aux/include/boost-1_47/boost/thread/pthread/thread_heap_alloc.hpp:24:47:   instantiated from ‘T* boost::detail::heap_new(A1&&) [with T = boost::detail::thread_data<boost::packaged_task<int> >, A1 = boost::packaged_task<int>&]’
/home/claudio/aux/include/boost-1_47/boost/thread/detail/thread.hpp:130:146:   instantiated from ‘static boost::detail::thread_data_ptr boost::thread::make_thread_info(F&&) [with F = boost::packaged_task<int>&, boost::detail::thread_data_ptr = boost::shared_ptr<boost::detail::thread_data_base>]’
/home/claudio/aux/include/boost-1_47/boost/thread/detail/thread.hpp:168:62:   instantiated from ‘boost::thread::thread(F&&) [with F = boost::packaged_task<int>&]’
answer.cc:17:36:   instantiated from here
/home/claudio/aux/include/boost-1_47/boost/thread/future.hpp:1268:9: error: ‘boost::packaged_task<R>::packaged_task(boost::packaged_task<R>&) [with R = int, boost::packaged_task<R> = boost::packaged_task<int>]’ is private
/home/claudio/aux/include/boost-1_47/boost/thread/detail/thread.hpp:49:21: error: within this context

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

namespace boost {
  using std::move;
}

works with MSVC 10 and GCC 4.5, 4.6.

comment:4 by viboes, 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.

Last edited 11 years ago by viboes (previous) (diff)

comment:5 by viboes, 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 viboes, 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 viboes, 11 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:8 by viboes, 11 years ago

Milestone: To Be DeterminedBoost 1.49.0

Committed in trunk at revision [76543].

comment:9 by viboes, 10 years ago

Milestone: Boost 1.49.0Boost 1.50.0
Resolution: fixed
Status: assignedclosed

Committed in release branch at [78543]

Note: See TracTickets for help on using tickets.