Fact #0: ZeroMQ was never thread-safe ( had Zero sharing Zen )
In spite of the most recent efforts ( published in late 2017 on 4.2+ total re-design efforts towards removing this known initial principle ), ZeroMQ education materials present wherever possible and also explain why there is a bad habit to try to share toys in distributed-system design practice.
Ad 2 )
Even if one gets some API-baked promise, always first benchmark the performance, if one will ever want to pay the costs of lost performance for such ex-post sharing doctrine. As noted about the ZeroMQ native API, there is principally nothing to be shared ( with one exception, which sometimes may make sense, the global Context()-instance ). Threads may "borrow" the IO-socket instantiations from such a global Context()-instance, but never share socket-instances, as the results are not guaranteed inside and under the ZeroMQ native API and so will not be any better even if promised so "above" any kind of higher level API.
Ad 3 ) No,
as per 2 ), never share sockets, there is no reason to try to do that. If managing resources ( and threads are first-class citizen among resources ), better create a private, point to point PAIR/PAIR
or PUSH/PULL
( even in tandem of simplex pipes ) over { inproc:// | ipc:// }
-transport-class ( where inproc://
can for performance motivated cases even use another "co-locally-isolated" private Context(0)
-instance, having indeed zero IO-threads at all ) and enjoy the due separation of concerns with minimum adverse effects on principally lost thread-safety ( if not doing so ) and performance.
Ad 1 + 4 )
( CZMQ/3.0.1 API docs ) zthread
- working with system threads (deprecated)
...
The zthread
class wraps OS thread creation. It creates detached threads that look like normal OS threads, or attached threads that share the caller's ØMQ context, and get an inproc
pipe to talk back to the parent thread. Detached threads create their own ØMQ contexts as needed. NOTE: this class is deprecated in favor of zactor
.
One may better check the version creeps among native API used, the binding / wrapper version and documentation.
Yet, Zero sharing Zen may lead your steps ( if selected language binding permits one to remain free in design decisions - reading the original design motivations always helps understand the performance and safety insights from The Original ).