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

From: Eli Zaretskii <[email-masked]>
Date: Mon, 27 Feb 2017 22:58:03 +0200

> From: Richard Copley <[email-masked]>
> Date: Mon, 27 Feb 2017 20:52:16 +0000
> Cc: Ken Brown <[email-masked]>, [email-masked]
> 
> Eli, you said:
> 
> > 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.
> 
> Posting a message and then sleeping while it's processed is odd,
> isn't it? If the input thread /sent/ its message to the main thread,
> then while waiting for SendMessage to return, the input thread would
> automatically continue to process sent messages

No, it's the main thread that calls SendMessage, to tell the input
thread to draw something.  And since the input thread is inside
'sleep', the SendMessage call never returns, and the main thread never
gets around to checking its input queue, where there's an event bound
to kill-emacs, waiting to be processed.