Subject: Re: bug#25875: 26.0.50; Hang logging out of MS-Windows

From: Eli Zaretskii <[email-masked]>
Date: Sun, 26 Feb 2017 17:44:51 +0200

> From: Richard Copley <[email-masked]>
> Date: Sat, 25 Feb 2017 21:07:51 +0000
> Cc: [email-masked]
> 
> On 25 February 2017 at 20:33, Eli Zaretskii <[email-masked]> wrote:
> >> From: Richard Copley <[email-masked]>
> >> Date: Sat, 25 Feb 2017 19:35:28 +0000
> >>
> >> On MS Windows, Emacs sometimes hangs when shutting down or logging out.
> >
> > How did you shut it down in this case?  This part:
> >
> >> #2  0x0000000400266caf in sys_sleep (seconds=1000)
> >>     at ../../repo/src/w32.c:3075
> >> No locals.
> >> #3  0x0000000400238225 in w32_wnd_proc (hwnd=0x1f076a, msg=22, wParam=1,
> >>     lParam=0) at ../../repo/src/w32fns.c:4805
> >
> > seems to indicate that you shut down your Windows session or
> > something?
> 
> Yes indeed. Hence "when shutting down or logging out". In this
> case shutting down the computer.

OK, supporting that is a relatively new feature, so it's little
surprise it needs more work.  Ken, could you please take a look?

As I understand it, this happens because when the input thread gets
the WM_ENDSESSION message, it posts it to the main thread and goes on
to sleep for 1000 sec, to avoid ending the Emacs process before it
finishes orderly shutdown.  But if the main thread happens to be
inside redisplay, it could invoke one of the function that send
messages to the input thread via SendMessage, which waits for the
input thread to respond.  So we do have a kind of deadlock.

One possible idea is to use SendMessageTimeout instead, with some
suitably chosen timeout.