Boost logo

Boost :

Subject: Re: [boost] Boost.Future & review of C++0x accepted libraries implementations
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-11-21 04:55:14


k-oli_at_[hidden] writes:

> Am Donnerstag, 20. November 2008 22:28:21 schrieb Anthony Williams:
>> k-oli_at_[hidden] writes:
>> > Am Donnerstag, 20. November 2008 18:19:12 schrieb Anthony Williams:
>> >> k-oli_at_[hidden] writes:
>> >> The latest C++0x working draft (which includes those papers, and which
>> >> is the "feature complete" committee draft out for voting at the
>> >> moment) is at:
>> >
>> > How has the jss::packaged_task to be used with boost::thread?
>> >
>> > X x;
>> > jss::packaged_task< std::string > tsk( boost::bind( & X::execute, x) );
>> > jss::shared_future< std::string > f( tsk.get_future() );
>> > boost::thread t(
>> > boost::bind(
>> > & jss::packaged_task< std::string >::operator(),
>> > tsk) );
>> > t.join();
>> > std::cout << f.get() << std::endl;
>> >
>> > Does not compile because packaged_task is noncopyable.
>> > In the C++0x working draft std::move( tsk) was used - but how to do it
>> > with the current boost release?
>>
>> boost::thread t(boost::move(tsk));
>
>
> Doesn't compile (gcc-4.3):
>
> conversion from 'jss::packaged_task<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > >' to non-scalar
> type 'boost::detail::thread_move_t<boost::thread>' requested
>
> Any ideas?

That's not the error message I get :-)

It's supposed to be taken care of with the move overload in
boost/thread/detail/move.hpp that binds to any T convertible to
thread_move_t<T> (which packaged_task is). Apparently that's broken.

To make it work, just provide an overload for packaged_task

namespace boost
{
    template<typename T>
    detail::thread_move_t<jss::packaged_task<T> > move(jss::packaged_task<T>& t)
    {
        return detail::thread_move_t<jss::packaged_task<T> >(t);
    }
}

Anthony

-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk