[nanomsg] Re: [Non-DoD Source] Re: On pthread_atfork(), and fork()-safe implementation

  • From: Franklin Mathieu <franklinmathieu@xxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Thu, 15 Dec 2016 10:09:34 +0100

2016-12-15 2:28 GMT+01:00 Garrett D'Amore <garrett@xxxxxxxxxx>:

Please refer to the Open Group specifications for this.  fork duplicates the
process memory image, but does not duplicate the threads themselves.  I take
that to mean the memory other than for the pthread itself will be
“duplicated”, and that if the only reference to said memory (directly or
indirectly) was on a stack frame for a thread that got left behind, then the
memory will be orphaned.

On Wed, Dec 14, 2016 at 1:57 PM, Karan, Cem F CIV USARMY RDECOM ARL (US)
<cem.f.karan.civ@xxxxxxxx> wrote:

Makes sense.  I can see how the standard library calls are difficult to
deal with; you have no control over how that memory is allocated.  I'm going
to expose my ignorance here; does fork() duplicate structures allocated by
pthreads?  I know it duplicates file descriptors, but I don't know what else
it duplicates.  Off hand, do you know of a complete list of what fork()
duplicates?


There are also corner cases w.r.t. file descriptors inheritance depending on
the platform.

A notable example I had with the current nanomsg codebase are kqueue file
descriptors, which are not inherited though fork().

-- 
Franklin "Snaipe" Mathieu
🝰 https://diacritic.io

Other related posts: