unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Cc: emacs-devel@gnu.org
Subject: Re: More info on sporadic OS/X crash
Date: Sat, 01 May 2004 20:32:49 +0900	[thread overview]
Message-ID: <wlfzakgz6m.wl@church.math.s.chiba-u.ac.jp> (raw)
In-Reply-To: <wz1xm9wiiz.fsf@Ordesa.local>

>>>>> On 27 Apr 2004 17:24:36 +0200, Piet van Oostrum <piet@cs.uu.nl> 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;
}

  parent reply	other threads:[~2004-05-01 11:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-15 23:15 More info on sporadic OS/X crash John Wiegley
2004-04-23 11:41 ` John Wiegley
2004-04-24  1:15   ` YAMAMOTO Mitsuharu
2004-04-25 17:49     ` Steven Tamm
2004-04-26 13:15       ` YAMAMOTO Mitsuharu
2004-04-26 16:27         ` Steven Tamm
2004-04-27  9:52           ` YAMAMOTO Mitsuharu
2004-04-27 15:24       ` Piet van Oostrum
2004-04-28  6:37         ` Eli Zaretskii
2004-04-28 11:14           ` Piet van Oostrum
2004-04-28 18:53             ` Eli Zaretskii
2004-04-29 12:10               ` Piet van Oostrum
2004-04-29 16:32                 ` Kim F. Storm
2004-04-29 22:24                   ` Steven Tamm
2004-04-29 22:25                   ` Piet van Oostrum
2004-05-01 11:32         ` YAMAMOTO Mitsuharu [this message]
2004-04-26 18:08     ` John Wiegley
2004-04-27  9:59       ` YAMAMOTO Mitsuharu
2004-04-29 22:08         ` John Wiegley
2004-05-01 11:09           ` YAMAMOTO Mitsuharu
2004-05-07  1:24             ` John Wiegley
2004-05-10  6:02             ` John Wiegley

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=wlfzakgz6m.wl@church.math.s.chiba-u.ac.jp \
    --to=mituharu@math.s.chiba-u.ac.jp \
    --cc=emacs-devel@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).