[zeromq-dev] How to safely use a socket in multiple threads in zmq 2.1.11
Thiago Cangussu
cangussu at gmail.com
Thu Jul 5 00:24:21 CEST 2012
Hi,
I have a pool of threads that needs to send messages to a zmq socket. I was
creating the socket, connecting, sending the message and closing it for
each message, but it is for sure not an optimal usage of resources, since
if I create/close sockets too fast, zmq is not able do release them as fast
and I get the error: "too many open files (signaler.cpp 330)". Since I have
no control over those threads, I'm about to try the following solution:
1 - create a pool of connected sockets (REQ, inproc)
2 - when a client thread wants to send a message, it grabs a socket from
the pool
3 - the thread performs a send/recv
4 - the thread releases the socket (which will be again available in the
pool)
The question is: what should I do to make this multi-threaded usage of
sockets safe? Is it enough to guarantee that multiple threads do not
perform send/receive simultaneously?
Thanks,
Thiago
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120704/dba017b0/attachment.htm>
More information about the zeromq-dev
mailing list