[zeromq-dev] How to safely use a socket in multiple threads in zmq 2.1.11

Ivan Pechorin ivan.pechorin at gmail.com
Thu Jul 5 08:35:13 CEST 2012


2012/7/5 Stephen Hemminger <shemminger at vyatta.com>

>
> You can have a per-thread pool of sockets, but you can't create socket
> in one thread and then use it in another.


You CAN create in one thread and then use it in another - just ensure
there's a memory barrier in the middle.


> Can you just have one socket
> per thread in thread local storage?
>

Sometime it's not feasible because you don't have control on these threads
and on their number.

For instance, if you develop some library or component that is intended to
run inside an existing application or app server, and this app or app
server uses lots (hundreds or even thousands) of threads, you will hit the
open file limit at some point if you create socket per thread when really
all you need is just a pool of few sockets.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120705/b0ffb641/attachment.htm>


More information about the zeromq-dev mailing list