[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 14:19:57 CEST 2012


On Thu, Jul 5, 2012 at 3:35 AM, Ivan Pechorin <ivan.pechorin at gmail.com>wrote:

> 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.
>

That's exactly the case. And there is also the problem that I need to close
the sockets before calling zmq_term. I actually tried this solution (TLS)
but it started to look like a code smell, so I revisited the muti-thread
use of sockets.

As a side note, the guide really did a good job keeping me away from using
sockets from multiple threads :)

Thanks,
Thiago
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120705/27c0ae4e/attachment.htm>


More information about the zeromq-dev mailing list