[zeromq-dev] Whcih API calls are thread safe ?

MinRK benjaminrk at gmail.com
Mon Jan 23 03:38:58 CET 2012


On Sun, Jan 22, 2012 at 00:28, Marten Feldtmann <itlists at schrievkrom.de> wrote:
> I would like to know, which APi calls can be used by different threads ?
>
> I assume, that ALL socket oriented calls MUST be called from the thread,
> which created the socket. Is this also true with the API call to close
> the socket ?

Yes, it certainly is.  I discovered this in pyzmq by trying to
replicate czmq's behavior of terminating a context implying the
closing of its sockets.  The problem was that this would crash if
sockets created by that context were actively in use (by poll, recv,
etc.) at the time close was being called.  I've since moved this
behavior into a separate Context.shutdown, with the disclaimer that it
is not a threadsafe action.

A simple (Python) example showing that `zmq_close(socket)` is not threadsafe:
https://gist.github.com/1660122

-MinRK

>
> The reason for my question is, that my binding to VASmalltalk uses
> several external threads - which allows me to have ZMQ running in my
> development image doing its work and I can change my domain code on the
> fly while my application is running.
>
> Therefore I have a mixture of synchronous API call (all is blocked) and
> asynchronous API call (by using an external thread) and I want to make
> sure, that I have found all API call, which MUST be called from the same
> thread.
>
>
> Marten
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev



More information about the zeromq-dev mailing list