[future William proposal] packaged_task do not accept boost::ref of a nullary functor

Hi, packaged_task do not accept boost::ref to nullary functions while thread allows it. Shouldn't packaged_task accept them? How can the user workaround this issue? How thread solved this issue? Thanks in advance, Vicente ===================== Compiler error: ../../../../boost/futures/future.hpp: In member function `void boost::detail::task_object<R, F>::do_run() [with R = int, F = boost::reference_wrapper<non_copyable_functor>]': test.cpp:250: instantiated from here ../../../../boost/futures/future.hpp:1206: error: no match for call to `(boost::reference_wrapper<non_copyable_functor>) ()' ===================== Here it is the code: struct non_copyable_functor : boost::noncopyable { unsigned value; typedef unsigned result_type; non_copyable_functor(): value(0) {} unsigned operator()() { value=999; return value; } }; void do_test_creation_through_reference_wrapper() { non_copyable_functor f; boost::packaged_task<unsigned > tsk(boost::ref(f)); tsk(); // COMPILER ERROR HERE //boost::future<unsigned > act = tsk.get_future(); //boost::thread thr(boost::move(tsk)); //unsigned res = act.get(); //BOOST_CHECK_EQUAL(res, 999u); //BOOST_CHECK_EQUAL(f.value, 999u); } _____________________ Vicente Juan Botet Escribá

----- Original Message ----- From: "vicente.botet" <vicente.botet@wanadoo.fr> To: <boost@lists.boost.org> Sent: Saturday, January 03, 2009 6:53 PM Subject: [boost] [future William proposal] packaged_task do not acceptboost::ref of a nullary functor
Hi,
packaged_task do not accept boost::ref to nullary functions while thread allows it. Shouldn't packaged_task > accept them? How can the user workaround this issue? How thread solved this issue?
I have found a workaround. Instead of boost::packaged_task<unsigned > tsk(boost::ref(f)); I use boost::packaged_task<unsigned> tsk(boost::bind(boost::ref(f))); Is this the correct way? Regards, Vicente

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
From: "vicente.botet" <vicente.botet@wanadoo.fr>
packaged_task do not accept boost::ref to nullary functions while thread allows it. Shouldn't packaged_task > accept them? How can the user workaround this issue? How thread solved this issue?
I have found a workaround. Instead of boost::packaged_task<unsigned > tsk(boost::ref(f)); I use boost::packaged_task<unsigned> tsk(boost::bind(boost::ref(f)));
Is this the correct way?
That's essentially what Boost.Thread does. 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

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Monday, January 05, 2009 12:49 PM Subject: Re: [boost] [future William proposal] packaged_task do notacceptboost::ref of a nullary functor
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
From: "vicente.botet" <vicente.botet@wanadoo.fr>
packaged_task do not accept boost::ref to nullary functions while thread allows it. Shouldn't packaged_task > accept them? How can the user workaround this issue? How thread solved this issue?
I have found a workaround. Instead of boost::packaged_task<unsigned > tsk(boost::ref(f)); I use boost::packaged_task<unsigned> tsk(boost::bind(boost::ref(f)));
Is this the correct way?
That's essentially what Boost.Thread does.
Given the prototypes: template<typename F> explicit thread(F func); template <class F> explicit packaged_task(F const& f): Shouldn't the prototype of packaged_task be template <class F> explicit packaged_task(F f): Shouldn't boost::thread(boost::ref(f)); fail or boost::packaged_task<unsigned> tsk(boost::ref(f)); succeed? What is the reason to make them different? Best, Vicente

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Monday, January 05, 2009 12:49 PM Subject: Re: [boost] [future William proposal] packaged_task do notacceptboost::ref of a nullary functor
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
From: "vicente.botet" <vicente.botet@wanadoo.fr>
packaged_task do not accept boost::ref to nullary functions while thread allows it. Shouldn't packaged_task > accept them? How can the user workaround this issue? How thread solved this issue?
I have found a workaround. Instead of boost::packaged_task<unsigned > tsk(boost::ref(f)); I use boost::packaged_task<unsigned> tsk(boost::bind(boost::ref(f)));
Is this the correct way?
That's essentially what Boost.Thread does.
Given the prototypes: template<typename F> explicit thread(F func);
template <class F> explicit packaged_task(F const& f):
Shouldn't the prototype of packaged_task be template <class F> explicit packaged_task(F f):
Shouldn't boost::thread(boost::ref(f)); fail or boost::packaged_task<unsigned> tsk(boost::ref(f)); succeed?
What is the reason to make them different?
Hmm. I'm not sure what the difference is with a plain ref(f). Boost.thread uses bind<void>(f,args) when you specify args in the constructor, but doesn't do anything for a plain function. I don't know why it wouldn't work with packaged_task, but I haven't tried it. I'll investigate. 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
participants (2)
-
Anthony Williams
-
vicente.botet