[zeromq-dev] Migrating ZMQ sockets acrossing threads

Pieter Hintjens ph at imatix.com
Fri Oct 26 03:14:18 CEST 2012

On Fri, Oct 26, 2012 at 2:03 AM, Kah-Chan Low <kahchanlow at yahoo.com> wrote:

> If I create a ZMQ socket, do not touch it direct or indirectly after this,
> and spawn a thread and hand over the pointer of socket to the new thread.
> The new thread is the only thread that perform operations on the socket,
> including deleting the socket.
> Is this the right way to migrate the socket across 2 threads?

Yes. When you create a new thread you automatically do a "full fence"
memory barrier.

This is how CZMQ creates a parent-to-child thread pipe, for example.
You can see that code in czmq/src/zthread.c

It's meant to be scary because we had so many people just sharing
sockets between threads and then wondering why 0MQ crashes so easily.


More information about the zeromq-dev mailing list