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 00:28:29 +0200 Message-ID: <87zju27yeq.fsf@inria.fr> References: <87li607c5l.fsf@gnu.org> <878v1nfqvn.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 1372977230 1643 80.91.229.3 (4 Jul 2013 22:33:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 4 Jul 2013 22:33:50 +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 00:33:51 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 1Uus60-0000h6-LC for guile-devel@m.gmane.org; Fri, 05 Jul 2013 00:33:48 +0200 Original-Received: from localhost ([::1]:43955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uus60-0006Le-8t for guile-devel@m.gmane.org; Thu, 04 Jul 2013 18:33:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uus5v-0006LW-Tc for guile-devel@gnu.org; Thu, 04 Jul 2013 18:33:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uus5u-0005yd-Kv for guile-devel@gnu.org; Thu, 04 Jul 2013 18:33:43 -0400 Original-Received: from hera.aquilenet.fr ([141.255.128.1]:50197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uus5u-0005yY-Af for guile-devel@gnu.org; Thu, 04 Jul 2013 18:33:42 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id ACE26576; Fri, 5 Jul 2013 00:28:30 +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 BtsGAtkvum9h; Fri, 5 Jul 2013 00:28:30 +0200 (CEST) Original-Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 07089546; Fri, 5 Jul 2013 00:28:29 +0200 (CEST) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 15 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 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:16512 Archived-At: Hi Mark, Mark H Weaver skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> We have this (since 2010): >> >> # define SCM_SYSCALL(line) \ >> do \ >> { \ >> errno =3D 0; \ >> line; \ >> if (errno =3D=3D EINTR) \ >> { \ >> SCM_ASYNC_TICK; \ >> continue; \ >> } \ >> } \ >> while(0) >> >> It turns out that the effect upon EINTR is to leave the loop. So >> typically, fport_fill_input just throws to system-error and reveals the >> EINTR, contrary to SCM_SYSCALL intends to do. > > Ugh. Well, I guess this finally explains . Indeed. (Funny to see how I was blissfully quoting the above macro saying: =E2=80=9Clook, EINTR is handled, of course!=E2=80=9D. :-)) > I strongly believe that we should fix this in stable-2.0. While it is > true that the above scenario is possible, I suspect it is at least an > order of magnitude more common for Guile-based software to be written > based on the presumption that EINTR is handled automatically. > > Not only did all versions of Guile 1.x automatically handle EINTR, but > most of us assumed that this behavior was unchanged in Guile 2.0 and > wrote our software based on that assumption. I certainly did. > > As it is now, even portable Scheme code that uses (read) might result in > exceptions being thrown semi-randomly. We cannot reasonably expect > Guile programs to put each (read) within a loop to handle EINTR. > > Please, let's fix this in stable-2.0. Yes, I=E2=80=99ve reached that conclusion too. I=E2=80=99ve been cooking a patch but the test case ends up being trickier = 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=9Cbetter= =E2=80=9D, but it fails without strace.) Suggestions? Thanks, Ludo=E2=80=99.