From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: busyloop in sigchld_handler Date: Sun, 11 Mar 2007 23:30:35 +0100 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1173652204 14850 80.91.229.12 (11 Mar 2007 22:30:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 11 Mar 2007 22:30:04 +0000 (UTC) Cc: emacs-devel@gnu.org To: sds@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 11 23:29:55 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HQWY7-0000hj-IB for ged-emacs-devel@m.gmane.org; Sun, 11 Mar 2007 23:29:55 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HQWYh-0004fU-Rb for ged-emacs-devel@m.gmane.org; Sun, 11 Mar 2007 17:30:31 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HQWYX-0004fO-GV for emacs-devel@gnu.org; Sun, 11 Mar 2007 18:30:21 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HQWYW-0004f3-JX for emacs-devel@gnu.org; Sun, 11 Mar 2007 18:30:20 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HQWYW-0004f0-Ef for emacs-devel@gnu.org; Sun, 11 Mar 2007 17:30:20 -0500 Original-Received: from pfepa.post.tele.dk ([195.41.46.235]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HQWXr-0002Bj-2C; Sun, 11 Mar 2007 18:29:39 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (0x503e2644.bynxx19.adsl-dhcp.tele.dk [80.62.38.68]) by pfepa.post.tele.dk (Postfix) with SMTP id 5B7C6FAC030; Sun, 11 Mar 2007 23:29:37 +0100 (CET) In-Reply-To: (Sam Steingold's message of "Sun\, 11 Mar 2007 17\:06\:07 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.95 (gnu/linux) X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:67752 Archived-At: Sam Steingold writes: > The following message is a courtesy copy of an article > that has been posted to gmane.emacs.devel as well. > >> * Kim F. Storm [2007-03-11 20:39:25 +0100]: >> >> Sam Steingold writes: >> >> Absolutely brilliant! I can confirm that it works. > > Thanks! Actually, I'm not quite sure your patch works. It seems the unresponsiveness is just delayed some seconds -- at least sometimes. I don't know what the system is doing -- flushing the buffer cache or some such? GNU Emacs 22.0.95.13 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars) Linux kernel: 2.4.20-8 > >> But can you explain why it works? > > wait3 is a system call, which, when invoked in a loop, prevents the > kernel from doing anything else (in this case, sending SIGCHLD to > emacs). sleep allows the kernel some time to pass the signal. > I tried to verify that there is a loop, but I can't. Apply the patch below, start emacs -Q, run M-x compile, and look at sigchld_pid array. I get this: (gdb) p sigchld_count $1 = 2 (gdb) p sigchld_sleep $2 = 8 (gdb) p sigchld_pid $3 = {1173651414, 0, 5453, 0, 1173651414, 0, -1, 10, 0 } So I'm puzzled what's going on. *** process.c 11 Mar 2007 20:32:23 +0100 1.501 --- process.c 11 Mar 2007 23:24:08 +0100 *************** *** 6468,6473 **** --- 6468,6478 ---- indirectly; if it does, that is a bug */ #ifdef SIGCHLD + + long sigchld_pid[20]; + int sigchld_count = 0; + int sigchld_sleep = 0; + SIGTYPE sigchld_handler (signo) int signo; *************** *** 6495,6505 **** #define WUNTRACED 0 #endif /* no WUNTRACED */ /* Keep trying to get a status until we get a definitive result. */ do { ! sleep (1); errno = 0; pid = wait3 (&w, WNOHANG | WUNTRACED, 0); } while (pid < 0 && errno == EINTR); --- 6500,6522 ---- #define WUNTRACED 0 #endif /* no WUNTRACED */ /* Keep trying to get a status until we get a definitive result. */ + + sigchld_count++; do { ! unsigned long t1, t2; ! /* sleep (1); */ ! time(&t1); errno = 0; pid = wait3 (&w, WNOHANG | WUNTRACED, 0); + if (sigchld_sleep < 15) + { + time(&t2); + sigchld_pid[sigchld_sleep++] = t1; + sigchld_pid[sigchld_sleep++] = t2 - t1; + sigchld_pid[sigchld_sleep++] = pid; + sigchld_pid[sigchld_sleep++] = errno; + } } while (pid < 0 && errno == EINTR); -- Kim F. Storm http://www.cua.dk