X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:mime-version:to:cc
	:subject:references:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=mWdDzhi3buJ8xS2Q
	y0LQ5+N/E3zvwD4Sp/Kmvp/KhaWNvpCxP2aIfS3NVZHLt8IJ41fOkdNJKxCE8/rn
	Sj/pogB3S+5h7s9g0XuHAdCrLsax6F8gknY709Yc/HDxII7cqg2BraLkRrfAeBpW
	jDY/aQ4LyKPt6hkZsg5LPTdnOOw=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:mime-version:to:cc
	:subject:references:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=X/NyblFybl4347lzzyiyUN
	M0z+4=; b=d6Pv5FGr+MW75ent0y/ybVDaJzcFeduuPG2a55XckKpLkIcY2CDArO
	O9YSq01jZrGAnipUtuQpVuHAx3KX/mr2Y4+vEfzVM0lvb5NXhpAU4QxpZNrpslnR
	z6eJPrMQWbYmfURV+7b4mvOa6lLfyBtIwbT0Mr1FESKTBQXdfV8Z8=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.1
Message-ID: <51BB56CB.7030209@cs.ucla.edu>
Date: Fri, 14 Jun 2013 10:45:47 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6
MIME-Version: 1.0
To: cygwin@cygwin.com
CC: 14569@debbugs.gnu.org
Subject: Re: bug#14569: 24.3.50; bootstrap fails on Cygwin
References: <b4m61xqu654.fsf@jpl.org> <51B5DA82.4010703@alice.it> <3EC77598-24B8-42DD-8983-5069E64AAB60@swipnet.se> <51B62175.10307@alice.it> <06F80BBC-D7CD-4E6C-97AD-EB8E476E2FC0@swipnet.se> <83sj0olh38.fsf@gnu.org> <51B7717D.6060702@cs.ucla.edu> <51B77A00.2060908@cornell.edu> <83mwqwl903.fsf@gnu.org> <51B78346.3050600@cornell.edu> <FA9D25B7-3D1F-40CC-AA6E-5347E8112CA4@swipnet.se> <E143AC75-8C2B-4A59-81F6-571B9D4EEF13@swipnet.se> <2E06A322-530C-4AA2-9282-6D2E48B1D194@swipnet.se> <51B8BEFE.6070309@cs.ucla.edu> <51B8D5ED.1010407@alice.it> <C679A2B2-0264-4DDA-B900-5B90BE7CF1E9@swipnet.se> <51BA03CA.4080804@cs.ucla.edu> <BEC82502-E9FD-4F8E-B91E-F680F6885FB2@swipnet.se>
In-Reply-To: <BEC82502-E9FD-4F8E-B91E-F680F6885FB2@swipnet.se>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Cygwin developers, I'm worried about a Cygwin bug where
pthread_kill may not send a signal to the correct thread.
This bug may be causing Emacs to crash.  The Cygwin bug is
discussed in this thread:

http://cygwin.com/ml/cygwin/2012-05/msg00472.html

Emacs uses pthread_kill to redirect
SIGCHLD to the main thread; if this is sent to a random
thread instead, that could explain the random crashes.

My question is: does this bug still exist with Cygwin,
and if so is it likely to get fixed soon?

More details about the Emacs bug can be found here:

  http://bugs.gnu.org/14569

Briefly, Emacs is crashing randomly on Cygwin ever since it started
doing this:

  /* Tickle glib's child-handling code.  Ask glib to wait for Emacs itself;
     this should always fail, but is enough to initialize glib's            
     private SIGCHLD handler.  */
  g_source_unref (g_child_watch_source_new (getpid ()));

After this newly-inserted code, Emacs finds out what the
child signal handler was:

  /* Now, find out what glib's signal handler was, and store it
     into lib_child_handler.  */
  struct sigaction action, old_action;
  emacs_sigaction_init (&action, deliver_child_signal);
  sigaction (SIGCHLD, &action, &old_action);
  eassert (! (old_action.sa_flags & SA_SIGINFO));
  if (old_action.sa_handler != SIG_DFL && old_action.sa_handler != SIG_IGN
      && old_action.sa_handler != deliver_child_signal)
    lib_child_handler = old_action.sa_handler;

Emacs's SIGCHILD handler, deliver_child_signal, arranges the
signal handling to occur in the main thread (to avoid races
within Emacs), like this:

  int old_errno = errno;
  bool on_main_thread = true;
  if (! pthread_equal (pthread_self (), main_thread))
    {
      sigset_t blocked;
      sigemptyset (&blocked);
      sigaddset (&blocked, sig);
      pthread_sigmask (SIG_BLOCK, &blocked, 0);
      pthread_kill (main_thread, sig);
      on_main_thread = false;
    }
  if (on_main_thread)
    handle_child_signal (sig);
  errno = old_errno;

And handle_child_signal, which runs in the main thread, does
a bunch of Emacsish things and then invokes lib_child_handler (sig),
which is glib's SIGCHLD handler.

All this works just fine on Fedora and other platforms; but it
doesn't work on Cygwin.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

