Subject: bug#25178: 26.0.50; Crash when pressing C-g in TTY mode

From: Eli Zaretskii <[email-masked]>
Date: Tue, 13 Dec 2016 21:37:27 +0200

> From: Andreas Schwab <[email-masked]>
> Cc: Elias Martenson <[email-masked]>,  [email-masked]
> Date: Tue, 13 Dec 2016 20:26:10 +0100
> 
> On Dez 13 2016, Eli Zaretskii <[email-masked]> wrote:
> 
> > Hmm...  Is calling pthread_mutex_unlock twice in a row, without an
> > intervening call to pthread_mutex_lock, supposed to segfault?
> 
> It's undefined, so anything can happen.  Just don't do that.

At this point, I'd like to establish whether the fact Emacs does do it
could explain crashes reported by Elias which I cannot reproduce on a
different GNU/Linux system.

What I think happens is that C-g on a TTY produces a SIGINT that
interrupts the call to pselect and runs handle_interrupt, which then
longjmps back to read_char, which then calls thread_select.  But since
pselect inside the previous call to thread_select was interrupted, the
following call to acquire_global_lock was not done, and we are now
running with the global lock unlocked.  Then thread_select calls
release_global_lock which attempts to unlock the (unlocked) mutex.

The question is whether this is just bad, or causes the crash.  It
doesn't crash for me.

Thanks.