[zeromq-dev] "Wakeup call" to a thread blocked inside zmq_poll()?

Chuck Remes lists at chuckremes.com
Mon Aug 13 23:54:57 CEST 2012

On Aug 13, 2012, at 1:05 PM, Arthur O'Dwyer wrote:

> Hi all,
> I'm trying to use ZMQ in what I guess (surprisingly to me) is an
> unconventional way. The salient points of our protocol are:
> - The connection has only two ends: exactly one client and exactly one server.
> - In fact, the labels "client" and "server" are mostly unnecessary;
> requests can originate on either side. Sometimes the client asks the
> server something, and sometimes the server asks the client something.
> - Answers to questions don't come right away (requests and replies are
> not nicely nested). If the client has two things to ask the server, it
> can do both requests at once, and the server can spawn two worker
> threads to compute the answers in parallel.
> I believe the architecture we need is a work queue on each side: when
> a client thread asks a question, it puts a request packet P_a and a
> timeout value T_a into the "outbox" and then waits on a condition
> variable associated with that transaction-ID. There's a master ZMQ
> thread with three responsibilies:
>    - Whenever the outbox is non-empty, pull a message from it and
> send it over the wire.
>    - Whenever a request comes in over the wire, spawn a new worker
> thread to handle that request.
>    - Whenever a reply comes in over the wire, match its
> transaction-ID to our list of waiting workers and notify the worker
> who's waiting for this particular reply.
>    - T_a seconds after the request P_a goes out over the wire, if the
> reply hasn't come yet, notify the waiting worker that the reply has
> timed out.
> Also, we'd like to have a "heartbeat" in both directions. But I
> believe that can easily be handled as a special kind of worker thread
> on each side, whose only job is to send a request every N seconds and
> complain if the reply times out.

If you look at Chapter 4 (I think) in the zeromq guide, take a look at the Majordomo protocol. It is essentially the same thing as what you seek here. There are many implementations in different languages, so you will have even less work to do.


More information about the zeromq-dev mailing list