Boost logo

Boost Users :

Subject: Re: [Boost-users] Communication between QThread and boost threads
From: Igor R (boost.lists_at_[hidden])
Date: 2013-02-13 13:19:51


> btw just curious, why didn't you call do_something_sync() directly in post()
> instead of through a lambda?

Without lambda I'd have to create a binder:
boost::bind(&class_name::do_something_sync, this). It's just a bit
more verbose :).
But in a real code there's also another point: usually it's preferable
to use shared_from_this idiom with async functions, to simplify
control over object lifetime.
So it would be either
{
  io_.post(bind(&class_name::do_something_sync, shared_from_this()));
}

or

{
  auto self = shared_from_this();
  io_.post([=] { self->do_something_sync(); });
}

...so the bind version already looks less verbose.


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