Boost logo

Boost Users :

Subject: Re: [Boost-users] Using unique_future in C++03, boost 1.47.0
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2011-12-13 18:16:15


Le 02/12/11 07:27, Kelvin Chung a écrit :
> I have a bunch of boost::packaged_task<unsigned long>, which I intend
> to execute on separate boost::threads. Before I do that, though, I
> want to insert each boost::unique_future<unsigned long> in a container
> as I make them. Given that I am using C++03 and boost 1.47.0 (boost
> 1.48.0 craps out over an ambiguous overload of boost::move), I have
> something like the following:
>
> std::deque<boost::unique_future<unsigned long>> futures;
> // std::deque<boost::thread> evalThreads; TODO
> for (…) {
> boost::packaged_task<unsigned long> task = …; // Create the
> tasks, one at a time
> boost::unique_future<unsigned long> taskResult = task.get_future();
> // boost::thread taskThread(boost::move(task)); TODO
>
> // boost::unique_future and boost::thread can't be copied, but can
> be moved
> futures.push_back(boost::move(taskResult));
> // evalThreads.push_back(boost::move(taskThread)); TODO
> }
> boost::wait_for_all(futures.begin(), futures.end());
> // Now we can do stuff with futures
>
> The problem is that the code above is failing to compile, saying that
>
> /usr/include/c++/4.1.2/ext/new_allocator.h:104: error: passing ‘const
> boost::unique_future<long unsigned int>’ as ‘this’ argument of
> ‘boost::unique_future<R>::operator
> boost::detail::thread_move_t<boost::unique_future<R> >() [with R =
> long unsigned int]’ discards qualifiers
>
> I don't fully understand the problem, but I blame the move emulation.
> How do I fix this?
>
Globally the move emulation on Boost.Thread is quite broken. There is a
plan to adapt it to Boost.Move which we hope will solve most of the
current issues.

I have tried to fix this with the current design I don't reach to find a
solution. I suspect that we will need to wait until the adaptation is
done if no one finds a trike solution.

Best,
Vicente


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net