From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: SCM_SYSCALL Date: Fri, 05 Jul 2013 22:01:48 +0200 Message-ID: <87d2qwu66r.fsf@gnu.org> References: <87li607c5l.fsf@gnu.org> <878v1nfqvn.fsf@tines.lan> <87zju27yeq.fsf@inria.fr> <878v1kbzuf.fsf@tines.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1373054817 30131 80.91.229.3 (5 Jul 2013 20:06:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 5 Jul 2013 20:06:57 +0000 (UTC) Cc: guile-devel@gnu.org To: Mark H Weaver Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jul 05 22:06:59 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UvCHR-0002FL-ML for guile-devel@m.gmane.org; Fri, 05 Jul 2013 22:06:57 +0200 Original-Received: from localhost ([::1]:44799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UvCHQ-0002cv-Nw for guile-devel@m.gmane.org; Fri, 05 Jul 2013 16:06:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UvCHN-0002cm-SY for guile-devel@gnu.org; Fri, 05 Jul 2013 16:06:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UvCHM-0005H1-8a for guile-devel@gnu.org; Fri, 05 Jul 2013 16:06:53 -0400 Original-Received: from hera.aquilenet.fr ([141.255.128.1]:52034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UvCHL-0005Gq-VM for guile-devel@gnu.org; Fri, 05 Jul 2013 16:06:52 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 71D63EF2; Fri, 5 Jul 2013 22:01:49 +0200 (CEST) Original-Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iZj3Si7Ikcdy; Fri, 5 Jul 2013 22:01:49 +0200 (CEST) Original-Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by hera.aquilenet.fr (Postfix) with ESMTPSA id C7A01546; Fri, 5 Jul 2013 22:01:48 +0200 (CEST) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 17 Messidor an 221 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: <878v1kbzuf.fsf@tines.lan> (Mark H. Weaver's message of "Fri, 05 Jul 2013 14:56:08 -0400") User-Agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 141.255.128.1 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16514 Archived-At: Hi Mark! Mark H Weaver skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> I=E2=80=99ve been cooking a patch but the test case ends up being tricki= er to >> write than I expected. Here=E2=80=99s 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 >> =E2=80=98system-error=E2=80=99 with EINTR. >> >> However, with a fixed SCM_SYSCALL, the result is pretty much the same as >> with SA_RESTART (see ): when SCM_ASYNC_TICK >> is called right after we get EINTR, chances are that the async hasn=E2= =80=99t >> 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 =E2=80=9Cbette= r=E2=80=9D, 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? I think the rationale was that signal handlers in Guile would be a simplified version of what POSIX provides. That is, they are called in the thread that called =E2=80=98sigaction=E2=80=99, and there are no restri= ctions on what procedures can be used from within the handler. From that perspective, I think it fits the bill. Now, of course that introduces concurrency, but that=E2=80=99s what signals= are about anyway: asynchronous notifications. Thus I don=E2=80=99t have any particular problems with this implementation. Am I overlooking other issues you had in mind? Thanks, Ludo=E2=80=99.