unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Nala Ginrut <nalaginrut@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: Andy Wingo <wingo@pobox.com>, guile-devel@gnu.org
Subject: Re: wip-threads-and-fork
Date: Thu, 22 Mar 2012 10:48:03 +0800	[thread overview]
Message-ID: <CAPjoZofRwWigLMARwaVWXsWn_PdR0pNeS5nU+F5LZ47Xg1aJ0Q@mail.gmail.com> (raw)
In-Reply-To: <8762dx7iiz.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3386 bytes --]

On Thu, Mar 22, 2012 at 5:26 AM, Ludovic Courtès <ludo@gnu.org> wrote:

> Hello!
>
> (With delay...)
>
> Andy Wingo <wingo@pobox.com> skribis:
>
> > I would have preferred this, but I came to the conclusion that this
> > approach is not sound.
>
> Without exposing ‘pthread_atfork’, how would you suggest making user
> code “fork-safe”?  A use case would be reviving the futures thread pool
> after ‘fork’.
>
> > Did you see that I merged the atfork bits into master?
> > (wip-threads-and-fork also had some CLOEXEC bits that needed more
> > baking).  They worked... sorta.  They had a few problems:
> >
> >   1) It's impossible to work around the lack of atfork() in libraries
> >      that you depend on.
> >
> >      For example, wip-threads-and-fork called fork() within the GC alloc
> >      lock, to get around the lack of a pthread_atfork() in libgc.  But
> >      then I submitted a patch to make libgc do this itself:
> >
> >
> http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/4940
> >
> >      It's pretty difficult to tell which version of libgc you would
> >      have.  There is no workaround that is sufficient.
>
> Indeed, good point.
>
> >   2) POSIX explicitly disclaims the result of calling non-signal-safe
> >      primitives after a fork() of a multithreaded program.
>
> Right, though reality seems to be more pleasant than POSIX. ;-)
>
> >   3) Nobody cares about these bugs.  See e.g. the lack of response at
> >      http://sourceware.org/bugzilla/show_bug.cgi?id=13725.  Even Bruno
> >      didn't reply to the Cc.  See point (2).
> >
> >   4) The atfork mechanism imposes a total ordering on locks.  This is
> >      possible for static locks, but difficult for locks on collectable
> >      Scheme objects.
> >
> >   5) Relatedly, just to be able to lock all weak tables at a fork, we
> >      had to create a new weak table-of-tables and add the tables to it.
> >      This is needless complication and overhead.
> >
> >   6) scm_c_atfork() is a broken interface.  Because it hangs its hooks
> >      off of one pthread_atfork() invocation, it can cause newer locks to
> >      insert themselves in the wrong position relative to
> >      pthread_atfork() calls made between when Guile installed the
> >      scm_c_atfork handler, and the call to scm_c_atfork.
> >
> >      There can be only one pthread_atfork() list, in a correct program.
>
> OK, thanks for the nice summary.  Indeed, this is a complex story.
>
> > In the end I reverted those patches because they were just complication
> > that didn't solve any fundamental problems.
>
> OK.
>
> > I came to the opinion, having run a threaded, forking program, that we
> > would be much better off if we provided good abstractions to spawn
> > processes, but that expecting fork() to work in a multithreaded program
> > is not realistic.
>
> Yes, things like ‘open-process’ make sense.
>
> What about adding a big fat warning in the doc about use of
> ‘primitive-fork’ in a multi-threaded program?
>

Please do it! My 5 cents.


>
> > Still, there is one other thing that perhaps we could do to shut down
> > the signal handling thread around a fork().  Dunno, perhaps it is worth
> > looking into.
>
> What would be the expected benefit?
>
> Thanks,
> Ludo’.
>
>

[-- Attachment #2: Type: text/html, Size: 4563 bytes --]

  reply	other threads:[~2012-03-22  2:48 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-08 22:10 wip-threads-and-fork Andy Wingo
2012-02-22 21:40 ` wip-threads-and-fork Andy Wingo
2012-02-23 15:05   ` wip-threads-and-fork Andy Wingo
2012-02-23 15:49     ` wip-threads-and-fork Nala Ginrut
2012-02-23 16:13       ` wip-threads-and-fork Andy Wingo
2012-02-24  3:00         ` wip-threads-and-fork Nala Ginrut
2012-02-24 10:21           ` wip-threads-and-fork Andy Wingo
2012-02-24 14:08             ` wip-threads-and-fork Nala Ginrut
2012-02-24 14:47               ` wip-threads-and-fork Andy Wingo
2012-02-24 15:25                 ` wip-threads-and-fork Nala Ginrut
2012-02-26 22:03             ` wip-threads-and-fork Ludovic Courtès
2012-02-27  9:44               ` wip-threads-and-fork Andy Wingo
2012-03-01 19:40                 ` wip-threads-and-fork Ludovic Courtès
2012-02-24 18:57           ` wip-threads-and-fork Andy Wingo
2012-02-25  2:21             ` wip-threads-and-fork Nala Ginrut
2012-02-25  2:30               ` wip-threads-and-fork Nala Ginrut
2012-02-25 18:01                 ` wip-threads-and-fork Andy Wingo
2012-02-26  2:35                   ` wip-threads-and-fork Nala Ginrut
2012-02-26 22:00     ` wip-threads-and-fork Ludovic Courtès
2012-02-27  9:39       ` wip-threads-and-fork Andy Wingo
2012-03-01 19:35         ` wip-threads-and-fork Ludovic Courtès
2012-03-03 16:32           ` wip-threads-and-fork Andy Wingo
2012-03-03 21:20             ` wip-threads-and-fork Ludovic Courtès
2012-03-04 11:38               ` wip-threads-and-fork Andy Wingo
2012-03-21 21:26                 ` wip-threads-and-fork Ludovic Courtès
2012-03-22  2:48                   ` Nala Ginrut [this message]
2012-03-23  9:40                   ` wip-threads-and-fork Andy Wingo
2012-03-27 15:54                     ` wip-threads-and-fork Ludovic Courtès
2012-04-06 18:30                       ` wip-threads-and-fork Andy Wingo
2012-04-07 22:54                         ` wip-threads-and-fork Ludovic Courtès
2013-01-17 11:41                           ` wip-threads-and-fork Andy Wingo
2012-03-01 19:32 ` wip-threads-and-fork Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPjoZofRwWigLMARwaVWXsWn_PdR0pNeS5nU+F5LZ47Xg1aJ0Q@mail.gmail.com \
    --to=nalaginrut@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=ludo@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).