[zeromq-dev] zmq_socket and threads

Pieter Hintjens ph at imatix.com
Thu Jan 3 11:11:50 CET 2013

On Wed, Jan 2, 2013 at 10:23 PM, Nishant Mittal <nmittal at rblt.com> wrote:

> the reason is ...
> 1) my application creates 5 threads, does some calcs and then the threads
> exit
> 2) this is done every minute. so every minute 5 new threads are created.
> 3) I think i will run into a file descriptor issue if i create sockets
> inside the thread (every time the thread is launched). so planning to create
> 5 sockets when my application starts and then use 1 socket from 1 thread.

You are solving entirely the wrong issue here.

Your architecture is wrong; creating and destroying threads and
sockets is a bad idea and unnecessary. Create your worker threads at
the start, send them work when it's available, and leave them running.
Create sockets in threads, use them locally, and _DO NOT_ share data,
especially sockets, between threads.

Sharing sockets between threads because you're afraid to create new
sockets is... very poor.


More information about the zeromq-dev mailing list