On Wed, 4 Jul 2012 19:24:21 -0300 Thiago Cangussu <[email protected]> wrote:
> 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 You can have a per-thread pool of sockets, but you can't create socket in one thread and then use it in another. Can you just have one socket per thread in thread local storage? _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
