Boost logo

Boost Users :

Subject: Re: [Boost-users] Can I use std::queue as ASIO io object for asynchronise operation?
From: Anthony Foiani (tkil_at_[hidden])
Date: 2012-03-31 02:34:06


Bruce --

"liubl" <809651688_at_[hidden]> writes:
> I want to implement a message queue between multiple thread, with
> multiple thread post message to the queue and one single thread process
> the message. I don't want the single processing thread to be blocked by
> the os when there is no message to be processed.
>
> I don't know if I can use ASIO lib to help me implement it. In my
> thought, the single processing thread read the queue asynchronisely and
> be invoked if there is one message ready on the queue, just like there
> is data ready on the socket.
>
> Is it doable? And is its performance better than the blocking method
> using conditional_variable?

It's probably not exactly the same thing, and I can't speak for
performance numbers, but I found the response to this question to be
very enlightening:

  http://stackoverflow.com/questions/7754695/boost-asio-async-write-how-to-not-interleaving-async-write-calls

The basic idea is to only access a particular resource from within a
single strand. I'm successfully using this pattern on one of my
projects.

Depending on how flexible you need your message queues to be, you
might also take a look at "Zero MQ":

   http://www.zeromq.org/

Happy hacking,
t.


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