unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: guile-devel <guile-devel@gnu.org>
Cc: Bruno Haible <bruno@clisp.org>
Subject: Re: wip-threads-and-fork
Date: Wed, 22 Feb 2012 22:40:40 +0100	[thread overview]
Message-ID: <878vjupmw7.fsf@pobox.com> (raw)
In-Reply-To: <877gzx0ye0.fsf@pobox.com> (Andy Wingo's message of "Wed, 08 Feb 2012 23:10:47 +0100")

Hi all,

An update on this issue.  For context:

On Wed 08 Feb 2012 23:10, Andy Wingo <wingo@pobox.com> writes:

> I was testing out the threaded web server and it was working well.  Then
> I tried it out with tekuti, a blog engine that uses git as the backend.
> It uses (ice-9 popen) to talk to the git binaries.  It was deadlocking
> and segfaulting and all kinds of things!
>
> The reason is that when you fork(), only the thread that calls fork()
> survives into the child.  If another thread was in a critical section --
> i.e., held a mutex -- it just stops.

One thing that I did not realize when I wrote this is that POSIX clearly
says that if a multithreaded program forks, the behavior of the child
after the fork is undefined if it calls any non-async-signal-safe
function before calling exec().

Go ahead and read that again, if you didn't catch it the first time.

Basically POSIX prohibits the generality of fork() if your program has
threads.  Guile has fork, and threads.  What to do?

Obviously we can treat the limited case of (ice-9 popen) in a more
portable fashion.

But then there is the question: why, in the name of all that is holy,
did POSIX specify pthread_atfork?  If its intention is to grab mutexes
around a fork, and mutex operations are not signal-safe, what are they
on about?

On Glibc, many things are likely to work.  Not all, of course -- witness
this bug:

> iconv_open() is threadsafe, but on glibc it loads gconv modules,
> within a lock.

Is the lack of a thread_atfork handler a glibc bug or not?  POSIX can
argue either way.

I filed http://sourceware.org/bugzilla/show_bug.cgi?id=13725 in any
case.  I'd rather not commit a workaround if it's a glibc bug, but what
about other platforms?  Do we in the Guile project have to choose
between threads and fork?

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2012-02-22 21:40 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 ` Andy Wingo [this message]
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                   ` wip-threads-and-fork Nala Ginrut
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=878vjupmw7.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=bruno@clisp.org \
    --cc=guile-devel@gnu.org \
    /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).