0

What I want to do is --> create a new object in a new thread. Something like:

Class* object = 0;
Arg arg;
boost::thread t( lambda::bind( object = lambda::new_ptr< Class >()( boost::ref( arg ) );

it doesn't compile, what's correct way?

Leo
  • 63
  • 1
  • 14
JQ.
  • 678
  • 7
  • 17
  • 2
    Hint: Use [Boost.Phoenix](http://www.boost.org/libs/phoenix/) rather than Boost.Lambda – the latter has been deprecated for years now. – ildjarn Feb 19 '13 at 01:19
  • 1
    If C++11 is an option for you, just do `std::thread t([&] { object = new Class(arg); } );` – Andy Prowl Feb 19 '13 at 01:38
  • Thanks guys, but I can't use C++11 right now. I'm going to try Phoenix... – JQ. Feb 19 '13 at 03:37

1 Answers1

0

Thanks to ildjarn, I tried with boost::phoenix and got it work, code is:

Class* object = 0;
CArg arg0;
Arg arg1;

boost::thread t( boost::phoenix::val( boost::ref( object ) ) = boost::phoenix::new_< Class >( boost::cref( arg0 ), boost::ref( arg1 ) );

Again, from ildjarn, the better code is:

Class* object = 0;

CArg arg0;

Arg arg1;

namespace phx = boost::phoenix;

boost::thread t( phx::ref( object ) = phx::new_< Class >( phx::cref( arg0 ), phx::ref( arg1 ) );

JQ.
  • 678
  • 7
  • 17
  • 1
    This should be `boost::thread t( phx::ref( object ) = phx::new_< Class >( phx::cref( arg0 ), phx::ref( arg1 ) );` (given `namespace phx = boost::phoenix;`). Notably, you should be using `ref`/`cref` from namespace `boost::phoenix` rather than namespace `boost`. – ildjarn Feb 20 '13 at 01:09