[nanomsg] Re: threading guidelines, and is traditional unix single threaded mode possible?

  • From: "Jason E. Aten" <j.e.aten@xxxxxxxxx>
  • To: nanomsg <nanomsg@xxxxxxxxxxxxx>
  • Date: Thu, 26 Sep 2013 13:13:14 -0700

On Thu, Sep 26, 2013 at 12:56 PM, Nico Williams <nico@xxxxxxxxxxxxxxxx>wrote:

> One way or another you'd have to ensure that by the time the child-side
> atfork handler runs the data structures are in a stable form, so it can
> do whatever the right thing is.  Doing this does not come at zero cost.
>
> > regularly on a global integer flag (the "please-prepare-to-fork flag")?
> At
> > most 2 poll intervals can elapse before every thread has noted the global
> > flag and then prepared by taking locks or otherwise pausing. You'd only
>
> That would be one way of doing it.  Kernel-side locks would be involved,
> so that that approach is not exactly lock-less :)
>

Right, so not zero cost globally, but if you don't fork, you don't pay for
kernel-side locks.  If you don't fork, you are
only having to have every thread read a global integer (latch) regularly.
Okay, epsilon cost, but negligible.

I'm confused by your comment about locking being required, or perhaps my
suggestion didn't land with you the way I described it. There would be no
kernel side locks, no locks whatsoever, involved on the non-forking path.

Other related posts: