[zeromq-dev] Thread Safe sockets

Joshua Foster jhawk28 at gmail.com
Tue Feb 7 01:37:28 CET 2012

I'm not sure if other languages have the same mechanism, but Java has a 
ThreadLocal object. It allows the developer to create and store objects 
local for each thread. In the ZMQ case, it would be an inproc socket for 
each thread so that we can hide the complexity of thread safety under 
the covers. If we do this, I would rather see completely new sockets 
like ZMQ_PUB_CONCURRENT instead of modifying the existing ones.

> +1, also from experience developing applications using ZeroMQ.
> The "each thread has its own inproc socket" model is really nice and we
> should emphasise it more. It leads to developing your applications
> around messaging and concurrency, and IMO is a much more elegant way of
> dealing with concurrency than the "old school" locks and shared state
> model.
> Can you elaborate on why such a socket would have to be stored as
> ThreadLocal? Given that in ZeroMQ a single listening (bound/connected)
> socket can have many other sockets connected to it, if threads A, B, C
> want to talk to thread D then A, B, C each have their own socket
> and all connect to D's inproc:// endpoint.
> -mato

More information about the zeromq-dev mailing list