[zeromq-dev] Sockets, Threads and Pooling
Brad LaFountain
blafountain at gmail.com
Thu Aug 25 17:24:58 CEST 2011
I've been trying to find out if its okay to use a socket across different
threads. I understand that i can't use them at the same time
across different threads, but I would implement this using some sort of
connection pool. So a single socket would be used in a single thread at any
given time, but that socket would be used in multiple threads in its
lifetime.
------------
Thread safety
A ØMQ *context* is thread safe and may be shared among as many application
threads as necessary, without any additional locking required on the part of
the caller.
Individual ØMQ *sockets* are *not* thread safe except in the case where full
memory barriers are issued when migrating a socket from one thread to
another. In practice this means applications can create a socket in one
thread with *zmq_socket()* and then pass it to a*newly created* thread as
part of thread initialization, for example via a structure passed as an
argument to *pthread_create()*.
---------------
>From this documentation it appears i'm not allowed to do this.
The problem is the data that i want to push out to a socket is being
executed in threads which i don't own.
void someCallbackInRandomThread(void *someData) {
zmqconnection c = pool.requestConnection();
c.sendMessage(someData);
pool.returnConnection(c);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110825/62d8a21a/attachment.htm>
More information about the zeromq-dev
mailing list