[zeromq-dev] Perennial thread safety question
Michael Powell
mwpowellhtx at gmail.com
Mon Apr 8 22:44:36 CEST 2013
On Mon, Apr 8, 2013 at 3:12 PM, Charles Remes <lists at chuckremes.com> wrote:
>
> On Apr 8, 2013, at 12:40 PM, Matthew Woehlke <matthew.woehlke at kitware.com>
> wrote:
>
> > 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.
>
> This is answered in the FAQ (http://www.zeromq.org/area:faq). Short
> answer is: Yes, go ahead and do this. If it crashes, protect the socket
> with some kind of memory barrier (e.g. mutex).
>
Apparently I sparked a productive discussion. Good progress, good feedback.
Thank ye.
> cr
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130408/4beb3a8f/attachment.htm>
More information about the zeromq-dev
mailing list