From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.devel Subject: Re: More info on sporadic OS/X crash Date: Sat, 01 May 2004 20:32:49 +0900 Organization: Faculty of Science, Chiba University Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: text/plain; charset=US-ASCII X-Trace: sea.gmane.org 1083411514 17374 80.91.224.253 (1 May 2004 11:38:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 1 May 2004 11:38:34 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sat May 01 13:38:26 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BJsp8-0006kR-00 for ; Sat, 01 May 2004 13:38:26 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BJsp8-0001WS-00 for ; Sat, 01 May 2004 13:38:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BJsnx-00047Q-6S for emacs-devel@quimby.gnus.org; Sat, 01 May 2004 07:37:13 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BJskw-0002kt-Ei for emacs-devel@gnu.org; Sat, 01 May 2004 07:34:06 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BJsjp-0002AI-L1 for emacs-devel@gnu.org; Sat, 01 May 2004 07:33:30 -0400 Original-Received: from [133.82.132.2] (helo=mathmail.math.s.chiba-u.ac.jp) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BJsjj-00022X-3n for emacs-devel@gnu.org; Sat, 01 May 2004 07:32:51 -0400 Original-Received: from church.math.s.chiba-u.ac.jp (church [133.82.132.36]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id D9CEE1A638A; Sat, 1 May 2004 20:32:49 +0900 (JST) Original-To: Piet van Oostrum In-Reply-To: User-Agent: Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.5 (Awara-Onsen) FLIM/1.14.5 (Demachiyanagi) APEL/10.6 Emacs/21.3.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:22494 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:22494 >>>>> On 27 Apr 2004 17:24:36 +0200, Piet van Oostrum said: > However now I have occasional hangs in select(), always when using > gnus. It could be a server that is not responding, but I am not > sure. I encountered the following situation (though I'm not sure whether it is related to the above one): 1. select (actually, sys_select in mac.c) is called from wait_reading_process_input. 2. Interrupt by SIGALRM occurs while ReceiveNextEvent in sys_select is being processed. 3. ReceiveNextEvent is called from XTread_socket again. 4. Emacs hangs. So at least ReceiveNextEvent in sys_select must be enclosed with BLOCK_INPUT/UNBLOCK_INPUT. Below is the sys_select function currently I'm using. Besides the above issue, I also modified the calculation of the remaining time for timeout and added a special handling for the common case where there are no subprocesses to be monitored. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp #include "blockinput.h" int sys_select (n, rfds, wfds, efds, timeout) int n; SELECT_TYPE *rfds; SELECT_TYPE *wfds; SELECT_TYPE *efds; struct timeval *timeout; { OSErr err; EMACS_TIME end_time, now, remaining_time; if (inhibit_window_system || noninteractive || rfds == NULL || !FD_ISSET (0, rfds)) return select(n, rfds, wfds, efds, timeout); if (wfds == NULL && efds == NULL) { int i; for (i = 1; i < n; i++) if (FD_ISSET (i, rfds)) break; if (i == n) { EventTimeout timeout_sec = (timeout ? (EMACS_SECS (*timeout) + EMACS_USECS (*timeout) / 1000000.0) : kEventDurationForever); BLOCK_INPUT; err = ReceiveNextEvent (0, NULL, timeout_sec, false, NULL); UNBLOCK_INPUT; if (err == noErr) { FD_ZERO (rfds); FD_SET (0, rfds); return 1; } else return 0; } } if (timeout) { remaining_time = *timeout; EMACS_GET_TIME (now); EMACS_ADD_TIME (end_time, now, remaining_time); } FD_CLR (0, rfds); do { EMACS_TIME select_timeout; SELECT_TYPE orfds = *rfds; int r; EMACS_SET_SECS_USECS (select_timeout, 0, 20000); if (timeout && EMACS_TIME_LT (remaining_time, select_timeout)) select_timeout = remaining_time; r = select (n, &orfds, wfds, efds, &select_timeout); BLOCK_INPUT; err = ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, NULL); UNBLOCK_INPUT; if (r > 0) { *rfds = orfds; if (err == noErr) { FD_SET (0, rfds); r++; } return r; } else if (err == noErr) { FD_ZERO (rfds); FD_SET (0, rfds); return 1; } if (timeout) { EMACS_GET_TIME (now); EMACS_SUB_TIME (remaining_time, end_time, now); } } while (!timeout || EMACS_TIME_LT (now, end_time)); return 0; }