[zeromq-dev] Thread Safe sockets

Martin Lucina martin at lucina.net
Tue Feb 7 07:57:07 CET 2012


On Tue, 07 Feb 2012 07:27:32 +0100
Marten Feldtmann <itlists at schrievkrom.de> wrote:

> -> thread safe socket
> 
> I'm not on a level as the other people on this list are, but I only 
> would like to be able to use creation/closing-socket-calls also be 
> possible from another thread (not acually using the socket). Is ths 
> possible - on all platforms ?

Context creation and destruction [zmq_init(), zmq_term()] - yes.
Socket creation [zmq_socket()] - yes.
Socket close [zmq_close()], and any other operation on an existing
socket - no.

In other words, you can safely create a socket in thread A, then do a
pthread_create (socket) and start using it in thread B.

You can destroy the socket's context from any thread, and any
in-progress or subsequent socket calls on that context will get
errno=ETERM back.

The context is only deallocated once you zmq_close() all sockets in it.
After that, any further calls on that context are undefined (i.e.
segfault or possibly EFAULT if you're lucky).

For more details see the manpages or http://api.zeromq.org/.

> Actually I like the way zeromq is done. The few API calls and the 
> external thread sending and receiving.

Thanks :-)

-mato
-- 
Martin Lucina <martin at lucina.net>



More information about the zeromq-dev mailing list