[zeromq-dev] Using multiple contexts

Pieter Hintjens ph at imatix.com
Sat Aug 13 17:20:05 CEST 2011


On Fri, Aug 12, 2011 at 8:11 PM, Christian Martinez <chmar at microsoft.com> wrote:

> Is there a downside to using multiple contexts? I have a class wrapper I’d
> like to keep as simple as possible. I can either modify it to allow multiple
> connects, sockets etc under a single context or leave it as is and have
> clients of the wrapper instantiate it multiple times.

I've been using multiple contexts in CZMQ, in the following way:

* I define two types of threads, attached and detached threads.
* Attached threads are structurally part of the main thread, and
connected by "pipes" over inproc. They share the same context.
* Detached threads are structurally separate, and connected by tcp://,
and they have their own context.

The advantage of this split is that you can always take a detached
thread and turn it in to a separate process, guaranteed that it will
work exactly the same way.

-Pieter



More information about the zeromq-dev mailing list