unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
To: sds@gnu.org
Cc: emacs-devel@gnu.org
Subject: Re: busyloop in sigchld_handler
Date: Sun, 11 Mar 2007 23:30:35 +0100	[thread overview]
Message-ID: <m3wt1nza44.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <m3wt1nlccg.fsf@loiso.podval.org> (Sam Steingold's message of "Sun\, 11 Mar 2007 17\:06\:07 -0400")

Sam Steingold <sds@gnu.org> writes:

> The following message is a courtesy copy of an article
> that has been posted to gmane.emacs.devel as well.
>
>> * Kim F. Storm <fgbez@phn.qx> [2007-03-11 20:39:25 +0100]:
>>
>> Sam Steingold <sds@gnu.org> 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 <repeats 12 times>}

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 <storm@cua.dk> http://www.cua.dk

  parent reply	other threads:[~2007-03-11 22:30 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-11 18:33 busyloop in sigchld_handler Sam Steingold
2007-03-11 19:39 ` Kim F. Storm
2007-03-11 19:43   ` David Kastrup
2007-03-11 19:51     ` Sam Steingold
2007-03-11 20:42       ` Kim F. Storm
2007-03-11 21:06   ` Sam Steingold
2007-03-11 21:14     ` Eli Zaretskii
2007-03-11 21:17       ` Sam Steingold
2007-03-11 21:51         ` Eli Zaretskii
2007-03-11 22:21           ` Sam Steingold
2007-03-12  4:24             ` Richard Stallman
2007-03-12  7:00               ` David Kastrup
2007-03-13  2:43                 ` Richard Stallman
2007-03-11 22:27     ` Andreas Schwab
2007-03-11 22:30     ` Kim F. Storm [this message]
2007-03-12 17:37     ` Andreas Schwab
2007-03-12 17:53       ` Sam Steingold
2007-03-12 18:45         ` Andreas Schwab
2007-03-12 18:57           ` Sam Steingold
2007-03-12 19:28             ` Andreas Schwab
2007-03-12 19:34               ` David Kastrup
2007-03-12 21:36                 ` Andreas Schwab
2007-03-13  7:29                   ` David Kastrup
2007-03-13  9:29                     ` Andreas Schwab
2007-03-13 22:19                       ` David Kastrup
2007-03-13 22:28                         ` Andreas Schwab
2007-03-13 22:54                           ` David Kastrup
2007-03-13 23:17                             ` Andreas Schwab
2007-03-14  7:06                               ` David Kastrup
2007-03-14  9:24                                 ` Kim F. Storm
2007-03-14 10:00                                   ` David Kastrup
2007-03-14 10:22                                     ` Andreas Schwab
2007-03-14 10:52                                       ` David Kastrup
2007-03-14 11:01                                         ` Andreas Schwab
2007-03-14 11:12                                           ` David Kastrup
2007-03-14 12:29                                             ` Andreas Schwab
2007-03-14 10:01                                   ` Andreas Schwab
2007-03-14 13:15                                     ` Kim F. Storm
2007-03-14 13:41                                       ` Andreas Schwab
2007-03-14 14:10                                         ` Kim F. Storm
2007-03-14 14:12                                           ` Andreas Schwab
2007-03-14 15:02                                             ` Kim F. Storm
2007-03-14 16:34                                               ` Andreas Schwab
2007-03-16  9:34                                                 ` Kim F. Storm
2007-03-16  9:59                                                   ` Andreas Schwab
2007-03-14  3:24                     ` Richard Stallman
2007-03-14 17:34                       ` David Kastrup
2007-03-26  1:47 ` YAMAMOTO Mitsuharu
2007-03-26  2:02   ` Sam Steingold
2007-03-26  2:17     ` YAMAMOTO Mitsuharu
2007-03-28 10:02     ` Kim F. Storm
2007-03-28 15:19       ` Chong Yidong
2007-03-28 15:25         ` Andreas Schwab
2007-03-28 15:33           ` Kim F. Storm
2007-03-28 15:37             ` Andreas Schwab
2007-03-28 20:18               ` Kim F. Storm
2007-03-29 17:59                 ` Richard Stallman
2007-03-28 15:30         ` Alfred M. Szmidt

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/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3wt1nza44.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=emacs-devel@gnu.org \
    --cc=sds@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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).