Boost logo

Boost Users :

Subject: Re: [Boost-users] problems with boost bind and boost thread
From: Gabriel Redner (gredner_at_[hidden])
Date: 2012-03-22 09:45:30


Try:

m_thread.reset(new
boost::thread(boost::bind(&CCycleThread::execute<T>,this,boost::protect(t))));

The gist of the problem is that nested binds do not work the way you
expect. For an explanation, see:
http://www.boost.org/doc/libs/1_48_0/libs/bind/bind.html#nested_binds

-Gabe

On Thu, Mar 22, 2012 at 4:56 AM, Marco <marco.schumann_at_[hidden]> wrote:
> Hi,
>
> I have problems with the attached code (test.cpp, extracted from the
> original class only with the relevant code).
> The member template  constructor of CCycleThread takes an argument and
> passes this to boost bind. The binding is to a another member template
> method which is the thread function for boost thread:
>
> boost::thread(boost::bind(&CCycleThread::execute<T>,this,t)
>
> The template parameter type is deduced by the argument type passed by the
> user.
>
> If the type is an ordinary function the code works fine. If the argument
> itself is another boost bind object the compilation fails!
>
> I tested the following within the constructor:
>
> auto test = boost::bind(&CCycleThread::execute<T>,this,t) // -> ok
> test(); // -> compile error
>
> The call of the operator() of the bind object is the problem.
>
> Interestingly, if one binding is boost::bind and the other one is std::bind
> the code works.
> Any ideas what's the problem? How can I fix this? Using std and boost bind
> is more a hack than a real solution :/
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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