[zeromq-dev] Perennial thread safety question

Matthew Woehlke matthew.woehlke at kitware.com
Mon Apr 8 19:40:11 CEST 2013


On 2013-04-08 08:37, Pieter Hintjens wrote:
> So "sharing sockets between threads" is really a non-question, it's
> only something people will try when they have not yet understood how
> to use 0MQ properly. The one exception to this general rule is in
> esoteric cases where you may create a socket in one thread, for use by
> an other thread.

I'm actually doing this. Essentially, I have a 'thread class' that has a 
run() method that is a thread entry point, but the ctor/dtor execute in 
the 'parent' thread.

Is it safe to create and set up, and tear down, my 0MQ socket in the 
ctor/dtor (i.e. in thread A, and poll/recv/etc. in thread B)? Is there 
something I should be doing to make it safe?

The class does guarantee that ctor/run()/dtor will never execute in 
parallel.

-- 
Matthew




More information about the zeromq-dev mailing list