[zeromq-dev] Thread safety of the ROUTER socket

Asbjørn Støen asbjorn.stoen at gmail.com
Fri Nov 29 15:51:00 CET 2013


in my Java app, I'm serving long-running requests from multiple clients on
a ROUTER socket. To achieve concurrency, I have one thread reading the
socket, and then I dispatch the request to a pool of worker threads. This
means that replies will be produced some time in the future by other
threads than the reader thread.

I'm aware that ØMQ sockets are not thread-safe, and of course, two threads
cannot send replies simultaneously to the same socket.

However, I would like some clarification on the concurrency of recv() and
send() operations:

1. Do I need to perform the recv() and send() sequentially (or preferrably
in one thread), as the doc seems to have it? Or:
2. Can I safely poll the socket for incoming messages while concurrently
sending a message from another thread? Or:
3. Can I safely receive messages in one thread while concurrently sending a
message from another thread?

The problem with #1 above is that polling the socket would block replies
from being sent for the duration of the poll. Non-blocking polls are of
course subject to spinlock. I'm hoping that at least #2 is true... although
#3 should be expected from an asynchronous socket.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131129/4e3dcc2c/attachment.htm>

More information about the zeromq-dev mailing list