Boost logo

Boost Users :

Subject: Re: [Boost-users] problems with Boost.Thread on VS10
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-04-06 12:59:00


Le 06/04/12 08:04, John M. Dlugosz a écrit :
> On 4/5/2012 2:32 AM, Igor R wrote:
>> Can you provide a trivial example that reproduces the issue?
>>
>

See below some points that don't work yet with Boost.
>
>
> #include "boost/test/unit_test.hpp"
> #include "boost/thread/future.hpp"
> #include "boost/utility/result_of.hpp"
> #include <functional>
>
> struct async_func {
> virtual ~async_func() { }
> virtual void run() =0;
> };
>
> template <typename Ret>
> class async_func_pt : public async_func {
> boost::packaged_task<Ret> f;
> public:
> void run() override { f(); }
> async_func_pt (boost::packaged_task<Ret>&& f) : f(std::move(f)) {}
Should't you use std::forward here?
> ~async_func_pt() { }
> boost::unique_future<Ret> get_future() { return f.get_future(); }
> };
>
> void async_core (async_func* p);
>
>
>
>
> template <typename F>
> boost::unique_future<typename boost::result_of< F() >::type>
> async (F&& f)
> {
> typedef typename boost::result_of< F() >::type RetType;
> async_func_pt<RetType>* p= new async_func_pt<RetType>
> (boost::packaged_task<RetType>(f));
> boost::unique_future<RetType> future_result= p->get_future();
> async_core (p);
> return std::move(future_result);
> }
>
> template <typename F, typename A1>
> boost::unique_future<typename boost::result_of< F(A1) >::type>
> async (F&& f, A1&& a1)
> {
> // This should be all it needs. But get a funny error deep inside Boost.
> // problem overloading with && ?
> return async (std::tr1::bind(f,a1));
> }
>
I don't think std::tr1::bind manage with rvalue references. Is this the
Boost version?
Have you tried using std::bind?
> BOOST_AUTO_TEST_SUITE(thread_pool_tests)
>
> int calculate_the_answer_to_life_the_universe_and_everything()
> {
> return 42;
> }
>
>
> size_t foo (const std::string& s)
> {
> return s.size();
> }
>
>
>
> BOOST_AUTO_TEST_CASE( async_test )
> {
> // this one works
> // most fundimental form:
> boost::unique_future<int> fi= async
> (&calculate_the_answer_to_life_the_universe_and_everything);
> int i= fi.get();
> BOOST_CHECK_EQUAL (i, 42);
>
>
> // This one chokes at compile time
> boost::unique_future<size_t> fut_1= async (&foo, "Life");
>
> BOOST_CHECK_EQUAL (fut_1.get(), 4);
> }
>
>
> BOOST_AUTO_TEST_SUITE_END()
>
>
As you are using std::move, &&, ... why not using directly the C++11
Thread library provided with the compiler?

BTW, Boost.Thread could not implement async using Boost, as Boost.Tuple,
Boost.Bind Boost.Fusion (Tuple) because these libraries dont manage with
rvalue references.

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