[zeromq-dev] Question about context and/or socket creation

Luca Boccassi luca.boccassi at gmail.com
Fri Sep 30 12:24:43 CEST 2016

You can (and probably should as best practise) reuse the context,
which is thread safe.

Do not use the same socket from multiple threads. There is a new
category of thread-safe sockets in libzmq master but the API is not
yet finalised.

On 30 September 2016 at 10:50, James Chapman <james at linux-101.org> wrote:
> [apologies if you've received this twice, first send was not from my
> subscribed email address and I'm not sure it actually went to the list]
> Hi all,
> Quick question regarding the creation of contexts and sockets. Some quick
> insight:
> I have a function that gets called from a thread pool that creates a
> context, a socket, sends a REQ message and waits for a REP, after which the
> socket is closed and then deleted. If the program runs for long enough, it
> eventually crashes, the last call being in zmq.hpp (line 657)
> zmq::socket_t::init(zmq::context_t & context_, int type_)
> {
> ...
>     ptr = zmq_socket (context_.ptr, type_ );   <--- Crash here
> So my question is basically, am I using contexts and sockets correctly by
> creating new instances each time I want to send a message or should I be
> re-using these as much as possible?
> Thanks
> _______________________________________________
> 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