unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: ludo@gnu.org, guile-devel@gnu.org
Subject: Re: [PATCH] Implement open-process and related functions on MinGW
Date: Sun, 23 Feb 2014 15:14:34 -0500	[thread overview]
Message-ID: <87sir9io2d.fsf@yeeloong.lan> (raw)
In-Reply-To: <83sir92044.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 23 Feb 2014 19:46:19 +0200")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Mark H Weaver <mhw@netris.org>
>> Cc: ludo@gnu.org,  guile-devel@gnu.org
>> Date: Sat, 22 Feb 2014 23:40:20 -0500
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> >> It's safe to fork a multithreaded program without using pthread_atfork
>> >> if only async-signal-safe functions are called before the exec.
>> >
>> > You may know what your code does between fork and exec, but you don't
>> > know what other parts do, like pthreads or the application that called
>> > Guile as a library.
>> 
>> I'm not sure I understand what you mean here.  The relevant code here is
>> between line 1366 (/* The child.  */) and the call to execvp on line
>> 1408.  I see calls to 'close', 'open', 'dup', and 'dup2'.
>> 
>> How could "pthreads" or "the application that called Guile" cause
>> anything else to happen between fork and exec in the new single-thread
>> child process?
>
> Pthreads could have locked some mutex before you fork, for example, in
> which case the child starts with a locked mutex and no live thread
> that will release it any time soon.

This is precisely why it's important to use only async-signal-safe
functions between fork and exec in the child process.  Such functions,
by contract, already have to cope with data structures (such as mutexes)
being in an inconsistent state that will never become consistent no
longer how long they wait, because the thread that has the mutex locked
(or is in the middle of locking/unlocking a mutex) might be the same
thread that the signal handler is running in.  They also cannot use
mutexes at all.

> The application could have done similar things, especially if it also
> uses threads, or some library that uses shared memory.

Any async-signal-safe function has to cope with this kind of thing, by
contract.

I don't know what else to say.  We have followed the widely recognized
guidelines for how fork+exec from a multithreaded program, as documented
in the POSIX spec and elsewhere.  If you still think there's a problem
here, please do the research and bring us something more specific, or
construct a test case that demonstrates a problem.

    Thanks,
      Mark



  reply	other threads:[~2014-02-23 20:14 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <wrbvbwejihe.fsf@sspiff.org>
     [not found] ` <wrbr471jxjg.fsf@sspiff.org>
     [not found]   ` <834n3x8o7m.fsf@gnu.org>
2014-02-17 20:59     ` [PATCH v2] Improved ^c support for gdb/guile Doug Evans
2014-02-17 21:13       ` Eli Zaretskii
2014-02-18  0:37         ` Doug Evans
2014-02-18 11:20           ` Ludovic Courtès
2014-02-18 16:01             ` Eli Zaretskii
2014-02-18 16:45               ` Ludovic Courtès
2014-02-18 16:56                 ` Eli Zaretskii
2014-02-18 17:45                   ` Ludovic Courtès
2014-02-18 17:59                     ` Eli Zaretskii
2014-02-18 23:08                       ` Ludovic Courtès
2014-02-18 17:32               ` MinGW patches Ludovic Courtès
2014-02-18 18:16                 ` Eli Zaretskii
2014-02-22 10:33                 ` [PATCH] Remove unneeded HAVE_POSIX conditionals Eli Zaretskii
2014-02-22 14:52                   ` Mark H Weaver
2014-02-22 15:41                     ` Eli Zaretskii
2014-02-26 21:42                     ` Ludovic Courtès
2014-02-22 10:50                 ` [PATCH] Implement open-process and related functions on MinGW Eli Zaretskii
2014-02-22 14:59                   ` Mark H Weaver
2014-02-22 15:43                     ` Eli Zaretskii
2014-02-22 15:54                   ` Mark H Weaver
2014-02-22 16:35                     ` Eli Zaretskii
2014-02-23  5:50                       ` Mark H Weaver
2014-02-23 17:54                         ` Eli Zaretskii
2014-02-24 18:33                           ` Mark H Weaver
2014-02-24 21:06                             ` Eli Zaretskii
2014-02-28  7:22                               ` Mark H Weaver
2014-02-28  9:10                                 ` Eli Zaretskii
2014-02-28 10:20                                   ` Mark H Weaver
2014-02-28 11:26                                     ` Eli Zaretskii
2014-02-24 21:12                             ` Eli Zaretskii
2014-02-22 18:20                     ` Eli Zaretskii
2014-02-22 22:02                       ` Mark H Weaver
2014-02-23  3:45                         ` Eli Zaretskii
2014-02-23  4:40                           ` Mark H Weaver
2014-02-23 17:46                             ` Eli Zaretskii
2014-02-23 20:14                               ` Mark H Weaver [this message]
2014-02-22 10:57                 ` MinGW patches Eli Zaretskii
2014-02-22 12:23                   ` Neil Jerram
2014-02-22 13:02                     ` Eli Zaretskii
2014-02-22 11:06                 ` Eli Zaretskii
2014-02-22 15:59                   ` Mark H Weaver
2014-02-22 16:36                     ` Eli Zaretskii
2014-02-23 14:21                       ` Mark H Weaver
2014-02-23 18:06                         ` Eli Zaretskii
2014-02-19  7:50               ` [PATCH v2] Improved ^c support for gdb/guile Mark H Weaver
2014-02-19 16:42                 ` Eli Zaretskii
2014-02-18 17:31             ` Doug Evans
2014-02-18 17:42               ` Signal delivery Ludovic Courtès
2014-02-18 17:56                 ` Doug Evans
2014-02-18 23:06                   ` Ludovic Courtès
2014-02-19  1:58                     ` Doug Evans

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=87sir9io2d.fsf@yeeloong.lan \
    --to=mhw@netris.org \
    --cc=eliz@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).