Boost logo

Boost Users :

Subject: Re: [Boost-users] Communication between QThread and boost threads
From: Igor R (boost.lists_at_[hidden])
Date: 2013-02-12 09:11:17


> The Gui is in Qt and Api is in boost. The Gui is meant to sit on top of Api.
> One of the functions of Api is to do network level data management, process
> data in certain ways and communicate with the Gui (ie., bridge Gui with
> other end of Api). To keep the GUI from freezing Api does it's work in a
> separate thread. If both Gui and Api had used Qt, communication would have
> been easier with cross-threaded signal-slot mechanism of Qt. Api emits and
> returns immediately and vice-versa. So none would be blocked unless
> explicitly specified (*Qt::BlockingQueuedConnection*). I've been using boost
> only since a while back as it was required to code new Api in boost. How do
> i achieve this mechanism in *boost <--> Qt communication*? Api is going to
> be header+static_library and so Gui and Api will produce single executable.
> I have to support Linux, Windows and Mac minimum.

You can emulate this behaviour using boost::asio::io_service::post():
in the Api layer make an "active object", whos interface functions
just post to the implementation:

class your_class
{
public:
  do_something()
  {
    io_service_.post([=] {do_something_sync();});
  }

private:
  do_something_sync()
  {
    // heavy processing
  }
};


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