unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Jan Djärv" <jan.h.d@swipnet.se>
Cc: 12471@debbugs.gnu.org, Juanma Barranquero <lekktu@gmail.com>
Subject: bug#12471: Avoid some signal-handling races, and simplify.
Date: Wed, 19 Sep 2012 12:58:23 -0700	[thread overview]
Message-ID: <505A23DF.3090301@cs.ucla.edu> (raw)
In-Reply-To: <357A45C4-8E4E-43AA-AF8B-BE2C5B056BA0@swipnet.se>

On 09/19/2012 09:45 AM, Jan Djärv wrote:> Hello.

> Thread sarted by Gnome/gtk+ plugins can not handle SIGALRM,
> so Emacs will terminate.

Thanks for looking at the patch.  Emacs doesn't terminate for me
(Fedora 17, GTK3), but perhaps that's because the problem is
specific to non-GNU/Linux platforms.  So could you please
explain the issue a bit more?

Here are some more details to help explain that part of the
proposed change.  In the Emacs trunk, a thread started by
those plugins can already get SIGALRM.  If it does, the
Emacs-supplied signal handler masks out SIGALRM in the
thread, resignals the process with SIGALRM so that some other
thread will get the signal next time, and then exits.  The
thread then resumes doing whatever it was doing, and the
main thread eventually gets signaled by SIGALRM.  So each
Gnome/gtk+ plugin thread might get signaled by SIGALRM,
altough it should handle that signal at most once.

Under the patch, a thread may handle SIGALRM more than once.
Each time it does so, it does something *very* simple (it
sets pending_signals to 1).  This shouldn't disturb what's
happening in the plugin thread, since the plugin thread
shouldn't be looking at pending_signals.

I've looked at the existing code, and tracked it back to
Emacs trunk bzr 58781 dated 2004-12-07, but couldn't find
any discussion of what the exact problem was.  Back then,
alarm timers could run lots of fancy code so it made sense
to insist that they run only in the main thread.  But
nowadays this should no longer be necessary.

The patch could be altered so that it retains the
signal-mask dance in the Gnome/gtk+ threads, but why bother?
Fidding with signal masks in a signal handler is
error-prone, because there are race conditions if the
interrupted code is itself fiddling with signal masks.  It's
OK to do this with handlers of fatal signals, because the
interrupted code won't be returned to, but for non-fatal
signals like SIGALRM it's problematic, and it's better to
avoid it if we don't need it.

If the above explanation doesn't suffice, could you please
give a recipe for reproducing the problem, or point me at a
bug report?  Thanks.






  reply	other threads:[~2012-09-19 19:58 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 23:39 bug#12471: Avoid some signal-handling races, and simplify Paul Eggert
2012-09-19 16:18 ` Eli Zaretskii
2012-09-20  6:07   ` Paul Eggert
2012-09-20 17:44     ` Eli Zaretskii
2012-09-21  7:42       ` Paul Eggert
2012-09-21  8:31         ` Eli Zaretskii
2012-09-21 17:26           ` Paul Eggert
2012-09-21 17:38             ` Eli Zaretskii
2012-09-21 18:13               ` Paul Eggert
2012-09-21 18:27                 ` Eli Zaretskii
2012-09-21 19:59                   ` Paul Eggert
2012-09-22  8:02                     ` Eli Zaretskii
2012-09-22  8:47                       ` Paul Eggert
2012-09-22  9:10                         ` Eli Zaretskii
2012-09-22  9:40                           ` Paul Eggert
2012-09-22 10:07                             ` Eli Zaretskii
2012-09-22 10:55                               ` Paul Eggert
2012-09-22 11:16                                 ` Eli Zaretskii
2012-09-22 20:28                               ` Stefan Monnier
2012-09-22 21:55                                 ` Paul Eggert
2012-09-23  3:55                                   ` Eli Zaretskii
2012-09-23  3:52                                 ` Eli Zaretskii
2012-09-19 16:45 ` Jan Djärv
2012-09-19 19:58   ` Paul Eggert [this message]
2012-09-20  6:27     ` Jan Djärv
2012-09-19 21:36 ` Andy Moreton
2012-09-23  9:36 ` bug#12471: installed into trunk Paul Eggert
2012-09-23 15:22   ` Andy Moreton
2012-09-23 16:23     ` Andy Moreton
2012-09-23 17:37       ` Juanma Barranquero
2012-09-23 17:37     ` Eli Zaretskii

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=505A23DF.3090301@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=12471@debbugs.gnu.org \
    --cc=jan.h.d@swipnet.se \
    --cc=lekktu@gmail.com \
    /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).