unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: SCM_SYSCALL
Date: Fri, 05 Jul 2013 14:56:08 -0400	[thread overview]
Message-ID: <878v1kbzuf.fsf@tines.lan> (raw)
In-Reply-To: <87zju27yeq.fsf@inria.fr> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22\?\= \=\?utf-8\?Q\?'s\?\= message of "Fri, 05 Jul 2013 00:28:29 +0200")

Hi Ludovic,

ludo@gnu.org (Ludovic Courtès) writes:
> I’ve been cooking a patch but the test case ends up being trickier to
> write than I expected.  Here’s what I have:
>
>         (let* ((in+out   (pk 'pipe (pipe)))
>                (lock     (make-mutex))
>                (cond     (make-condition-variable))
>                (signaled #f)
>                (thread   (call-with-new-thread
>                           (lambda ()
>                             (with-mutex lock
>                               (display "hello " (cdr in+out))
>                               (wait-condition-variable cond lock)
>                               (display "world\n" (cdr in+out))
>                               (close-port (cdr in+out)))))))
>           (define handle
>             (lambda (signum)
>               (with-mutex lock
>                 (set! signaled (pk 'sig signum))
>                 (signal-condition-variable cond))))
>           (sigaction SIGALRM handle 0)
>           (alarm 2)
>
>           ;; This thread (the main thread) receives the signal.  Yet,
>           ;; the EINTR returned by read(2) as called via `read-line'
>           ;; must be swallowed.
>           (let ((line (read-line (car in+out))))
>             (join-thread thread)
>             (list signaled line)))
>
> This nicely reproduces the problem where fport_fill_input throws to
> ‘system-error’ with EINTR.
>
> However, with a fixed SCM_SYSCALL, the result is pretty much the same as
> with SA_RESTART (see <http://bugs.gnu.org/14640>): when SCM_ASYNC_TICK
> is called right after we get EINTR, chances are that the async hasn’t
> been queued yet, so we get back to our read(2) call, and thus the
> Scheme-level signal handler is never called.  (Typically, when running
> the test through strace, it passes, because the timing is “better”, but
> it fails without strace.)
>
> Suggestions?

Hmm.  Shouldn't our signal handlers be run in a different thread?  Maybe
we can't make this change until 2.2, but it seems to me that there are
very serious problems trying to run signal handlers from within asyncs,
analogous to the problems running finalizers within asyncs.  Commonly,
signal handlers need to mutate some global state, but that cannot in
general be done safely from within asyncs, because asyncs might be
called while the global state is in an inconsistent state, at least for
data structures implemented in Scheme.

What do you think?

      Mark



  reply	other threads:[~2013-07-05 18:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-23 21:25 SCM_SYSCALL Ludovic Courtès
2013-07-03 18:19 ` SCM_SYSCALL Mark H Weaver
2013-07-04 22:28   ` SCM_SYSCALL Ludovic Courtès
2013-07-05 18:56     ` Mark H Weaver [this message]
2013-07-05 20:01       ` SCM_SYSCALL Ludovic Courtès
2013-07-06 16:41         ` SCM_SYSCALL Mark H Weaver
2013-07-06 21:05           ` SCM_SYSCALL Ludovic Courtès
2013-07-17 16:04 ` SCM_SYSCALL Ludovic Courtès
2014-03-23 19:56 ` SCM_SYSCALL Andy Wingo

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=878v1kbzuf.fsf@tines.lan \
    --to=mhw@netris.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).