unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel@gnu.org
Subject: Re: wip-threads-and-fork
Date: Thu, 01 Mar 2012 20:40:32 +0100	[thread overview]
Message-ID: <87vcmo5cun.fsf@gnu.org> (raw)
In-Reply-To: <87mx848vbo.fsf@pobox.com> (Andy Wingo's message of "Mon, 27 Feb 2012 10:44:11 +0100")

Hi,

Andy Wingo <wingo@pobox.com> skribis:

> On Sun 26 Feb 2012 23:03, ludo@gnu.org (Ludovic Courtès) writes:
>
>> Andy Wingo <wingo@pobox.com> skribis:
>>
>>>     +  if (scm_ilength (scm_all_threads ()) != 1)
>>>     +    /* Other threads may be holding on to resources that Guile needs --
>>>     +       it is not safe to permit one thread to fork while others are
>>>     +       running.
>>>     +
>>>     +       In addition, POSIX clearly specifies that if a multi-threaded
>>>     +       program forks, the child must only call functions that are
>>>     +       async-signal-safe.  We can't guarantee that in general.  The best
>>>     +       we can do is to allow forking only very early, before any call to
>>>     +       sigaction spawns the signal-handling thread.  */
>>>     +    SCM_MISC_ERROR ("attempt to fork while multiple threads are running",
>>>     +                    SCM_EOL);
>>
>> Just like fork(2) lets one shoot themself in the foot, I think this is
>> beyond libguile’s scope.  After all, libguile just wraps the OS
>> features, however crippled they may be.
>
> Dunno.  That is certainly the case for things like close-fdes, and the
> FFI.  But if someone really wants an unsafe fork, the FFI can give it to
> them, right?  Keep in mind that portably speaking, you can't even call
> `malloc' in the child, if you forked a program with multiple threads.

How so?

> Primitive-fork is much less necessary now that open-process, the most
> important use case, has been rewritten in C.

That’s right.

Another option would be to expose ‘pthread_atfork’ to Scheme.  It would
allow, for instance, (ice-9 futures) to register a child-side handler to
create a new thread pool, which would sound useful to me.

WDYT?

Thanks,
Ludo’.



  reply	other threads:[~2012-03-01 19: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 ` 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                 ` Ludovic Courtès [this message]
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=87vcmo5cun.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@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).