Skip to content Skip to sidebar Skip to footer

Moving A Zeromq Socket To Another Thread

The ZeroMQ guide states that sockets shouldn't be shared between threads. However, in the Pyre ZeroMQ project, at some point in the zhelper module a socket is created in a thread t

Solution 1:

You can pass a socket to another thread when you put a memory barrier between. Locks and other synchronisation primitives use memory barriers, so yeah, you can use any synchronisation primitives to just wrap your socket.

What I would, however, like to point out is that having to wrap a socket in a mutex usually says that something is wrong with your architecture. What you should do is to set up multiple inproc sockets, each thread owning one or more sockets, and have the threads talk to each other via these inproc sockets rather than exchanging sockets using mutexes.

Post a Comment for "Moving A Zeromq Socket To Another Thread"