GNU bug report logs - #25214
26.0.50; Interacting with user from threads other than the primary

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Eli Zaretskii <eliz@HIDDEN>; merged with #32426; dated Fri, 16 Dec 2016 15:19:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Merged 25214 32426. Request was from Michael Albinus <michael.albinus@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 19 Dec 2016 04:31:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Dec 18 23:31:52 2016
Received: from localhost ([127.0.0.1]:46704 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1cIpc7-0005Ro-Jz
	for submit <at> debbugs.gnu.org; Sun, 18 Dec 2016 23:31:52 -0500
Received: from eggs.gnu.org ([208.118.235.92]:50168)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <clement.pit@HIDDEN>) id 1cIpc5-0005RX-HN
 for submit <at> debbugs.gnu.org; Sun, 18 Dec 2016 23:31:49 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <clement.pit@HIDDEN>) id 1cIpby-0001XT-Uy
 for submit <at> debbugs.gnu.org; Sun, 18 Dec 2016 23:31:44 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:54194)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <clement.pit@HIDDEN>)
 id 1cIpby-0001XP-RV
 for submit <at> debbugs.gnu.org; Sun, 18 Dec 2016 23:31:42 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41139)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <clement.pit@HIDDEN>) id 1cIpbw-0006dw-Kx
 for bug-gnu-emacs@HIDDEN; Sun, 18 Dec 2016 23:31:42 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <clement.pit@HIDDEN>) id 1cIpbt-0001Ux-EM
 for bug-gnu-emacs@HIDDEN; Sun, 18 Dec 2016 23:31:40 -0500
Received: from mout.kundenserver.de ([217.72.192.74]:58126)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <clement.pit@HIDDEN>)
 id 1cIpbt-0001UF-46
 for bug-gnu-emacs@HIDDEN; Sun, 18 Dec 2016 23:31:37 -0500
Received: from [18.189.127.106] ([18.189.127.106]) by mrelayeu.kundenserver.de
 (mreue102 [212.227.15.184]) with ESMTPSA (Nemesis) id
 0Lm4KP-1crtNW0UbJ-00ZdRP for <bug-gnu-emacs@HIDDEN>; Mon, 19 Dec 2016
 05:31:35 +0100
Subject: Re: bug#25214: 26.0.50; Interacting with user from threads other than
 the primary
To: bug-gnu-emacs@HIDDEN
References: <837f6z9a4x.fsf@HIDDEN>
From: =?UTF-8?Q?Cl=c3=a9ment_Pit--Claudel?= <clement.pit@HIDDEN>
Message-ID: <4ab8f369-393d-3c72-9abf-d68d6880151b@HIDDEN>
Date: Sun, 18 Dec 2016 23:31:28 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.5.1
MIME-Version: 1.0
In-Reply-To: <837f6z9a4x.fsf@HIDDEN>
Content-Type: multipart/signed; micalg=pgp-sha256;
 protocol="application/pgp-signature";
 boundary="t0Fj4ohbQ3HTGkthfNTJG902RKKwi1mjV"
X-Provags-ID: V03:K0:KkwI9tTJ3J16Bb8enF5Xuy17FA+oH/RdWqVvOHcz/5niTcApGIj
 ZvfpfYEJ+mL6MXmyHJwdYrlMcCtMVtlrGRupwmm9xwbO3G9Cc6j6mecwkx3nwiv/Q65HwIk
 UWuT3y+mZPYhW+jTJ+EsMmjGw5eRZwnI9ZWdyxOpMfcb+27rr26KJkCWsALpKlOhKX2dxrh
 d76ohLNVYLBObStJLFRbQ==
X-UI-Out-Filterresults: notjunk:1;V01:K0:eAAhubqfXS4=:1V0CHqB0rUeD27eRx49F3X
 JXh8OxiL11NtoX2lXbcwS9JD8GetFZJaX2hQc78E3Y/bBiRBJzLRHM20vr2G2YibPMo7VmTaF
 n9k1/VckldaickqEhqYWATZ8+PrP1Te+IohqiWKM8FRZJakWoMEwVfffCS6bWM5J3Nv1QU/Ff
 PWYBMD16BtQIlnkyATRYt3ti7nQRKZKKFh75UH/tkl/ANbTpzOqqR2X77rlhvQE0C/debeWhC
 NA4YuKloNyDZyT7SKV9Dn+W/5mRjWVyoRVu2MDOlrAdHLC1FWdLd5ikjQRh2kc/2spWoDwCL3
 w4Mk2oIu0liZxtOLLMDUwhcXhC5BNJV8LxVp0owgNnH98WgMbfFHLezTzYQfTkNXkec/CfkNz
 r6K02z10P5oXAFdW2oEp5Lcps0rb3WyTpoQLP/wXIO229CQAx9lsZ3gzCsm279iZKmFsj37IW
 a6z7Z+EfEkhUx/3j0/IQaM8CvYW4lwHWiZYHbLjnZuTH9/C5TtBl2uBvefa5lZNVRmS6m1jyq
 VWhP77RNvMNW5nWIawTr0ZiuiyjWV88EDHSiFVEV0AQAXnOWYFnOseFIx6+RdvNwy8HfcfDTL
 TAB9MMr5RZOA0VpmQVmUyM/ptVq6zu44uFWn7JB9vyqnn7wdU25x0LfEBVFuNoNmnS5bLDqJf
 5jX7ipM9i3FuT8DdH5OjZtE7ApWJp/U2ihVxWKOF4kmZg2VVDCpjwUqQjyXsCz/eyeaU=
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--t0Fj4ohbQ3HTGkthfNTJG902RKKwi1mjV
Content-Type: multipart/mixed; boundary="P1CDDCW2e9ga49k3VrVD5uaa7BjXeA6iS";
 protected-headers="v1"
From: =?UTF-8?Q?Cl=c3=a9ment_Pit--Claudel?= <clement.pit@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Message-ID: <4ab8f369-393d-3c72-9abf-d68d6880151b@HIDDEN>
Subject: Re: bug#25214: 26.0.50; Interacting with user from threads other than
 the primary
References: <837f6z9a4x.fsf@HIDDEN>
In-Reply-To: <837f6z9a4x.fsf@HIDDEN>

--P1CDDCW2e9ga49k3VrVD5uaa7BjXeA6iS
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

Hi Eli,

> Thoughts?

I don't have that much concurrency experience, but this sounds like an is=
sue that other languages have had to deal with in the context of GUIs.  I=
n Microsoft's Windows Forms, for example, applications start with a singl=
e thread (the UI thread) running a message pump, and other threads that w=
ant to interact with the user may do so only by posting a message (using =
Control.Invoke) to the UI thread.

If I understand your description of the problem correctly, what happens i=
s essentially that the main thread and the background thread are competin=
g for keyboard access.  If so, could the solution be to route all UI requ=
ests through the main thread?  Concretely, this would mean that in the co=
ntext of a secondary thread, calling "read-from-minibuffer" really means =
pushing a message (tagged with a thread id) into a queue of "pending-read=
s-from-minibuffer", then repeatedly `thread-yield`ing until the UI thread=
 has pushed the user's response into a map of "processed-reads-from-minib=
uffer".  The user's response would be collected by the main thread.

Alternatively, could we simply disallow this type of interaction until we=
 have a good story about it? That would bring us closer to the way web wo=
rkers work in Javascript (they need to post a message to interact with th=
e UI/DOM).

Cheers,
Cl=E9ment.

On 2016-12-16 10:17, Eli Zaretskii wrote:
> Here's some fun with threads:
>=20
>  emacs -Q
>=20
> Evaluate:
>=20
>   (defun my-question ()
>     (let (use-dialog-box) ;; in case this is a GUI frame
>       (if (y-or-n-p "Yes or no? ")
> 	  (message "You said YES")
> 	(message "You said NO"))))
>=20
> Evaluate:
>=20
>   (my-question)
>=20
> You get a question asked in the minibuffer, answer it with Y or N, and
> get the corresponding echo.  All's well.
>=20
> Now evaluate this:
>=20
>   (make-thread #'my-question "question")
>=20
> You again get the question asked in the minibuffer, but typing
> anything at the prompt causes Emacs to complain that whatever you
> typed is "undefined".  Your only fire escape is to close this session
> with some mouse gesture, or kill it.
>=20
> What happens here is that, by the time the new thread runs, the main
> (a.k.a. "primary") thread is already idle, i.e. it already called
> read_char, which called wait_reading_process_output, which called
> thread_select.  (In fact, it's _because_ the primary thread called
> thread_select that the new thread was allowed to run at all, since it
> has to acquire the global lock for that, and that is only possible
> when the running thread releases the lock inside thread_select.)  Now,
> when wait_reading_process_output calls thread_select, it prepares the
> mask for file descriptors it will wait for to become ready for
> reading, in this case there's only one descriptor: the keyboard
> descriptor.  So the primary thread is waiting for input from the
> keyboard.
>=20
> Now the new thread starts running and eventually calls y-or-n-p, which
> calls read_char, which calls wait_reading_process_output.  But when
> this call prepares the mask for the thread_select call, it skips the
> keyboard descriptor, because we only allow a single thread to wait on
> each descriptor, and the keyboard descriptor is already watched by the
> primary thread.  So the new thread ends up not waiting on the keyboard
> input descriptor.
>=20
> The thread_select call then switches back to the primary thread, and
> the primary thread receives the Y or N character you type.  But it
> doesn't know what to do with it, so it becomes confused.
>=20
> IOW, user interaction from non-primary threads is currently inherently
> unsafe.
>=20
> And then, of course, there's the use case where two threads ask the
> user something via the minibuffer.
>=20
> Thoughts?
>=20
>=20
>=20
> In GNU Emacs 26.0.50.118 (i686-pc-mingw32)
>  of 2016-12-16 built on HOME-C4E4A596F7
> Repository revision: fb2fdb1435d2520c1cbf2a3d6a53128512a38458
> Windowing system distributor 'Microsoft Corp.', version 5.1.2600
> Recent messages:
> For information about GNU Emacs and the GNU system, type C-h C-a.
>=20
> Configured using:
>  'configure --prefix=3D/d/usr --enable-checking=3Dyes,glyphs --with-wid=
e-int
>  --with-modules 'CFLAGS=3D-O0 -gdwarf-4 -g3''
>=20
> Configured features:
> XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
> TOOLKIT_SCROLL_BARS MODULES
>=20
> Important settings:
>   value of $LANG: ENU
>   locale-coding-system: cp1255
>=20
> Major mode: Lisp Interaction
>=20
> Minor modes in effect:
>   tooltip-mode: t
>   global-eldoc-mode: t
>   electric-indent-mode: t
>   mouse-wheel-mode: t
>   tool-bar-mode: t
>   menu-bar-mode: t
>   file-name-shadow-mode: t
>   global-font-lock-mode: t
>   font-lock-mode: t
>   blink-cursor-mode: t
>   auto-composition-mode: t
>   auto-encryption-mode: t
>   auto-compression-mode: t
>   line-number-mode: t
>   transient-mark-mode: t
>=20
> Load-path shadows:
> None found.
>=20
> Features:
> (shadow sort mail-extr emacsbug message subr-x puny seq byte-opt gv
> bytecomp byte-compile cl-extra help-mode cconv cl-loaddefs pcase cl-lib=

> dired dired-loaddefs format-spec rfc822 mml easymenu mml-sec
> password-cache epa derived epg epg-config gnus-util rmail rmail-loaddef=
s
> mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
> mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
> mail-utils time-date mule-util tooltip eldoc electric uniquify
> ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table
> term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset imag=
e
> regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mod=
e
> lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer
> select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
> term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
> vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
> hebrew greek romanian slovak czech european ethiopic indian cyrillic
> chinese composite charscript case-table epa-hook jka-cmpr-hook help
> simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs button
> faces cus-face macroexp files text-properties overlay sha1 md5 base64
> format env code-pages mule custom widget hashtable-print-readable
> backquote w32notify w32 multi-tty make-network-process emacs)
>=20
> Memory information:
> ((conses 16 102990 12105)
>  (symbols 56 21101 0)
>  (miscs 48 36 129)
>  (strings 16 21030 4737)
>  (string-bytes 1 593607)
>  (vectors 16 14398)
>  (vector-slots 8 444812 4412)
>  (floats 8 179 129)
>  (intervals 40 269 104)
>  (buffers 864 11))
>=20
>=20
>=20
>=20


--P1CDDCW2e9ga49k3VrVD5uaa7BjXeA6iS--

--t0Fj4ohbQ3HTGkthfNTJG902RKKwi1mjV
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJYV2KlAAoJEPqg+cTm90wjc6IQAJM8Im7ioxuNgHSgR1MaDFJn
uSZ1Rz/2qxPH1S+6RWPnci10r2eCcTmyOGJDSB0urYzQj+Drns5c/6I440J4NVAe
8hbebqnsDNCmeShnqtjzkBDc5FWQkGBS50VgCePLFWKdOL8vPSe+dKe/DcE00Jvg
WtwlWiYb8QLhD3itLAjoNxgqf17ReWf7Al2CRz6jy9P8UfvMjwyHij8zfep0oAap
nWcXwG5XYolx73hEFmd7p7KVYPVZduI1d+pDMwUCa/U5UqJjGymHKldwUNAAfmfj
E52e2xJ22Uo1lefUmUQKZFyi73ZeToOI0A+bhdBl+gwnjMyC9o950/K5w1nezrrz
N+hey44O+LApjD8IjbWobc9WHHLKBpplYfCc6p1nNS8NNyWwDwTIkxFNjDG2o8CZ
T+9QCte97ikDhmvwDHtZeugrOvD1XUfJjUNUkKrqIeK5CbF/HGKXIEiG3UyJ7tiS
OF89pbIkPYG0KznwCmCRyfHT8i8zPvDTMarMSuOXtZ0i0p1ELZqQvfLzluMKIUMf
KZByN3IrfjMwd+hHpvuOUj0EscAM4Tm97OkxWmj4xDEBNild2L/IFG7N9CQq5bhy
RU5DnjRofGYdo0/mQlZrM5xV7+hftRzfG6RJ8cmuQrDqh0Xnka8NZ0/fHUw7CJku
yDo3dAv0vInoI1e36iFx
=xRZM
-----END PGP SIGNATURE-----

--t0Fj4ohbQ3HTGkthfNTJG902RKKwi1mjV--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#25214; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 16 Dec 2016 15:18:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Dec 16 10:18:23 2016
Received: from localhost ([127.0.0.1]:44437 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1cHuH9-0001Gq-7N
	for submit <at> debbugs.gnu.org; Fri, 16 Dec 2016 10:18:23 -0500
Received: from eggs.gnu.org ([208.118.235.92]:34609)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1cHuH7-0001Ge-Ha
 for submit <at> debbugs.gnu.org; Fri, 16 Dec 2016 10:18:21 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <eliz@HIDDEN>) id 1cHuH1-00083N-0Z
 for submit <at> debbugs.gnu.org; Fri, 16 Dec 2016 10:18:16 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_50,RP_MATCHES_RCVD
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:55813)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <eliz@HIDDEN>) id 1cHuH0-00083J-TW
 for submit <at> debbugs.gnu.org; Fri, 16 Dec 2016 10:18:14 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:53813)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <eliz@HIDDEN>) id 1cHuGz-0003Oa-Df
 for bug-gnu-emacs@HIDDEN; Fri, 16 Dec 2016 10:18:14 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <eliz@HIDDEN>) id 1cHuGu-000825-EU
 for bug-gnu-emacs@HIDDEN; Fri, 16 Dec 2016 10:18:13 -0500
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54805)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@HIDDEN>)
 id 1cHuGY-0007w8-9l; Fri, 16 Dec 2016 10:17:46 -0500
Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2799
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1cHuGX-0008Ez-9E; Fri, 16 Dec 2016 10:17:46 -0500
Date: Fri, 16 Dec 2016 17:17:02 +0200
Message-Id: <837f6z9a4x.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 26.0.50; Interacting with user from threads other than the primary
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -8.1 (--------)
X-Debbugs-Envelope-To: submit
Cc: Tom Tromey <tom@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Eli Zaretskii <eliz@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -8.1 (--------)

Here's some fun with threads:

 emacs -Q

Evaluate:

  (defun my-question ()
    (let (use-dialog-box) ;; in case this is a GUI frame
      (if (y-or-n-p "Yes or no? ")
	  (message "You said YES")
	(message "You said NO"))))

Evaluate:

  (my-question)

You get a question asked in the minibuffer, answer it with Y or N, and
get the corresponding echo.  All's well.

Now evaluate this:

  (make-thread #'my-question "question")

You again get the question asked in the minibuffer, but typing
anything at the prompt causes Emacs to complain that whatever you
typed is "undefined".  Your only fire escape is to close this session
with some mouse gesture, or kill it.

What happens here is that, by the time the new thread runs, the main
(a.k.a. "primary") thread is already idle, i.e. it already called
read_char, which called wait_reading_process_output, which called
thread_select.  (In fact, it's _because_ the primary thread called
thread_select that the new thread was allowed to run at all, since it
has to acquire the global lock for that, and that is only possible
when the running thread releases the lock inside thread_select.)  Now,
when wait_reading_process_output calls thread_select, it prepares the
mask for file descriptors it will wait for to become ready for
reading, in this case there's only one descriptor: the keyboard
descriptor.  So the primary thread is waiting for input from the
keyboard.

Now the new thread starts running and eventually calls y-or-n-p, which
calls read_char, which calls wait_reading_process_output.  But when
this call prepares the mask for the thread_select call, it skips the
keyboard descriptor, because we only allow a single thread to wait on
each descriptor, and the keyboard descriptor is already watched by the
primary thread.  So the new thread ends up not waiting on the keyboard
input descriptor.

The thread_select call then switches back to the primary thread, and
the primary thread receives the Y or N character you type.  But it
doesn't know what to do with it, so it becomes confused.

IOW, user interaction from non-primary threads is currently inherently
unsafe.

And then, of course, there's the use case where two threads ask the
user something via the minibuffer.

Thoughts?



In GNU Emacs 26.0.50.118 (i686-pc-mingw32)
 of 2016-12-16 built on HOME-C4E4A596F7
Repository revision: fb2fdb1435d2520c1cbf2a3d6a53128512a38458
Windowing system distributor 'Microsoft Corp.', version 5.1.2600
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Configured using:
 'configure --prefix=/d/usr --enable-checking=yes,glyphs --with-wide-int
 --with-modules 'CFLAGS=-O0 -gdwarf-4 -g3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS MODULES

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1255

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message subr-x puny seq byte-opt gv
bytecomp byte-compile cl-extra help-mode cconv cl-loaddefs pcase cl-lib
dired dired-loaddefs format-spec rfc822 mml easymenu mml-sec
password-cache epa derived epg epg-config gnus-util rmail rmail-loaddefs
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript case-table epa-hook jka-cmpr-hook help
simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs button
faces cus-face macroexp files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote w32notify w32 multi-tty make-network-process emacs)

Memory information:
((conses 16 102990 12105)
 (symbols 56 21101 0)
 (miscs 48 36 129)
 (strings 16 21030 4737)
 (string-bytes 1 593607)
 (vectors 16 14398)
 (vector-slots 8 444812 4412)
 (floats 8 179 129)
 (intervals 40 269 104)
 (buffers 864 11))




Acknowledgement sent to Eli Zaretskii <eliz@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#25214; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 13 Aug 2018 12:15:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.