[zeromq-dev] Context delayed creation

Martin Sustrik sustrik at 250bpm.com
Wed Sep 7 08:56:21 CEST 2011

Hi Pieter,

> Something we discussed a few times but never implemented: delaying
> context creation to allow configuration.


> The way this is done in CZMQ is to create the context when it's first
> used, i.e. first socket is created. You might need an extra API
> function to explicitly initialize a context if you want to pass it to
> child threads in parallel.

Actually, you don't. Creation of socket can be placed into mutex as it's 
out of critical path and thus the first call to zmq_socket() can simply 
lock the context properties causing subsequent attempts to set them to 
return error.

> The API would become:
> zmq_ctx_t *context = zmq_ctx_new ();
> zmq_ctx_set_iothreads (context, N); // if N not 1
> zmq_ctx_set_maxsockets (context, M); // if M not = 512
> zmq_ctx_set_maxvsmsize (context, S);

What about:

int zmq_sysctl (int option, void *value, size_t size);


More information about the zeromq-dev mailing list