unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Michael Welsh Duggan <mwd@md5i.com>
Cc: emacs-devel@gnu.org
Subject: Re: User interaction from multiple threads
Date: Wed, 15 Aug 2018 10:02:13 +0200	[thread overview]
Message-ID: <87600cukfu.fsf@gmx.de> (raw)
In-Reply-To: <87bma4528z.fsf@md5i.com> (Michael Welsh Duggan's message of "Tue, 14 Aug 2018 12:42:04 -0400")

Michael Welsh Duggan <mwd@md5i.com> writes:

Hi,

>> Use case #1:
>>
>>   . The main thread is waiting for user input.  The user didn't yet
>>     type anything
>>   . A non-main thread runs Lisp that prompts the user for some input
>>
>>   In this case, we probably want the following input to go to the
>>   prompting thread, right?  But it might also be the case that the
>>   user actually wants the input to go to the main thread, e.g. to
>>   perform some unrelated command.  Should we allow that?  If yes, how
>>   should Emacs know which thread should receive what the user types?
>>
>> Use case #2:
>>
>>   Same as the previous, but now the user is in the middle of typing a
>>   key sequence, when the non-main thread prompts.  For example,
>>   suppose the user has typed "C-x".
>>
>>   What do we want to happen now?  Do we "preempt" the main thread and
>>   let the following input to go to the prompting thread?  Or do we let
>>   the prompting thread wait until the main thread reads a full key
>>   sequence and runs the command bound to it?  If the former, what to
>>   do with the partial key sequence ("C-x") that the user typed?  If
>>   the latter, how do we indicate to the user that there is a prompt
>>   from another thread?
>>
>> Use case #3:
>>
>>   Similar, but now 2 or more non-main threads prompt the user, one
>>   after the other, in quick succession.  What should happen now, and
>>   how will the user know there are multiple prompts?
>
> #1 If "waiting for input" means in read-from-minibuffer or something
>    similar, I believe that input should go to the the thread.  The other
>    thread will have to wait.  If "waiting for input" means idle, it
>    should go the the other thread.

I agree. If there is already a prompt in the minibuffer, the input shall
be related to that prompt. If the user wants to do something else (enter
a command for the main thread), she shall cancel the existing prompt with C-g.

Maybe we shall mark the requesting thread for user input somehow, for
example by a modeline indicator with related help-echo.

> #2 You should neveer break a key sequence.  We do not preempt the main
>    thread.  The other thread will have to wait.

I agree. If a user has started typing input, no other thread shall
interrupt this by showing its own prompt, and reading own input. The
other thread has to wait.

> #3 Each thread should get to ask its question in turn, with its own
>    prompt.  Other threads will block until that question is answered.
>    The user will know there are multiple prompts because after they
>    answer one, they get asked another.

Agreed. The prompts must be designed such a way, that a user knows what
she is responding to. She cannot expect a defined order of the prompts.

For example, when answering a question about a file, the prompt shall
always contain the file name the question is related to.

> User input has to have a beginning and an end.  The simple cases are
> easy: a single full key sequence or a read-from-minibuffer call.  But in
> many cases an application has a series of prompts to be asked and
> answered in succession.  So these inputs need to be able to be grouped
> somehow along with their prompts.  Then, once a group is executing, any
> other input-related groups raised by other threads have to wait for the
> current input group to finish.  Then they cay be served in FIFO or
> random order.
>
> The easiest was I can think of grouping sets of inputs is as some form
> of critical section, maybe implemented by mutexes.  This would be
> simplified for the programmer with a convenience wrapper, something like
> (with-input-group BODY) or some such.

Would be useful for new and adapted code.

> Unfortunately, this proposal suffers in that it would have to be
> retroactively added to existing code.  So for existing code, some form
> of heuristic will have to be used instead.  The only one that comes to
> mind is this: Once an input sequence begins, input is locked to that
> thread until that thread ends, explicitly ends input operations (with
> some new directive), or (in the case of the main thread) returns to the
> command loop.  Now, I can see problems with that.  What happens when a
> thread prompts for input and then sits and blocks waiting for something
> else?  Unless we can categorize certain blocking operations as ones that
> will release the input mutex.

I don't agree with this heuristic. Even if we don't run into deadlocks,
one thread with a simple y-or-n-p question would block all other threads
until it finishes, which could take time. We must accept that for not
adapted code user input is requested from different threads, in random
order. The only guarantee is, that user input for the same thread is in
predefined order.

Over the time, code will be adapted for threads to use the grouping
feature as proposed above.

> Sorry, this was very much stream-of-thought.  

Same here.

Best regards, Michael.



  reply	other threads:[~2018-08-15  8:02 UTC|newest]

Thread overview: 119+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-14 15:12 User interaction from multiple threads Eli Zaretskii
2018-08-14 16:42 ` Michael Welsh Duggan
2018-08-15  8:02   ` Michael Albinus [this message]
2018-08-16 14:25   ` Eli Zaretskii
2018-08-17  2:59     ` Michael Welsh Duggan
2018-08-17  8:56       ` Eli Zaretskii
2018-08-15  8:06 ` martin rudalics
2018-08-15  8:22   ` Michael Albinus
2018-08-15  9:08     ` martin rudalics
2018-08-15 10:30       ` Michael Albinus
2018-08-15 12:27         ` martin rudalics
2018-08-15 12:59           ` Michael Albinus
2018-08-15 16:27             ` Elias Mårtenson
2018-08-15 18:04               ` Michael Albinus
2018-08-17  4:26                 ` Elias Mårtenson
2018-08-17  4:32                   ` Elias Mårtenson
2018-08-17  7:33                   ` Michael Albinus
2018-08-17  7:48                     ` Elias Mårtenson
2018-08-17  8:11                       ` Michael Albinus
2018-08-17  9:02                       ` Eli Zaretskii
2018-08-15 16:55           ` Eli Zaretskii
2018-08-16 12:21             ` martin rudalics
2018-08-16 13:46               ` Eli Zaretskii
2018-08-17  7:24                 ` martin rudalics
2018-08-17  7:48                   ` Eli Zaretskii
2018-08-17  8:34                     ` martin rudalics
2018-08-17  8:52                       ` Eric Abrahamsen
2018-08-17  9:06                       ` Michael Albinus
2018-08-17  9:12                       ` Eli Zaretskii
2018-08-18  8:31                         ` martin rudalics
2018-08-18  9:32                           ` Eli Zaretskii
2018-08-19  9:17                             ` martin rudalics
2018-08-15 16:47   ` Eli Zaretskii
2018-08-16 12:20     ` martin rudalics
2018-08-16 13:45       ` Eli Zaretskii
2018-08-16 15:19         ` Michael Albinus
2018-08-20 14:36     ` Gemini Lasswell
2018-08-20 15:06       ` Eli Zaretskii
2018-08-19 23:08 ` Gemini Lasswell
2018-08-20  1:18   ` Phil Sainty
2018-08-20 14:15     ` Gemini Lasswell
2018-08-20 17:07       ` Eli Zaretskii
2018-08-29 17:36         ` John Shahid
2018-08-30  0:18           ` Phil Sainty
2018-08-30  2:34             ` John Shahid
2018-08-30 13:10               ` Eli Zaretskii
2018-08-30 16:08                 ` John Shahid
2018-08-30 17:38                   ` Eli Zaretskii
2018-08-30 20:15                     ` John Shahid
2018-08-31 18:06                       ` Eli Zaretskii
2018-08-31 21:37                       ` Gemini Lasswell
2018-09-01  7:00                         ` Eli Zaretskii
2018-08-20 17:03   ` Eli Zaretskii
2018-08-20 22:38     ` Phil Sainty
2018-08-21 15:09       ` Eli Zaretskii
2018-08-22  4:05         ` Richard Stallman
2018-08-22 14:28           ` Eli Zaretskii
2018-08-22 15:48             ` hw
2018-08-22 17:33               ` Eli Zaretskii
2018-08-22 19:34                 ` hw
2018-08-22 23:58               ` Richard Stallman
2018-08-23  0:22                 ` John Wiegley
2018-08-24  1:59                   ` Richard Stallman
2018-08-23 14:08                 ` Eli Zaretskii
2018-08-23 22:34                   ` Phil Sainty
2018-08-24  8:51                     ` Eli Zaretskii
2018-08-24 12:59                       ` Phil Sainty
2018-08-25  0:21                       ` Richard Stallman
2018-08-25  0:16                     ` Richard Stallman
2018-08-24  2:00                   ` Richard Stallman
2018-08-24  3:57                     ` Elias Mårtenson
2018-08-24  9:20                     ` Eli Zaretskii
2018-08-24 11:44                       ` Michael Albinus
2018-08-24 15:41                         ` Elias Mårtenson
2018-08-25 11:58                           ` Michael Albinus
2018-08-27 10:53                             ` Elias Mårtenson
2018-08-25  0:20                       ` Richard Stallman
2018-08-25  7:51                         ` Eli Zaretskii
2018-08-25 10:32                           ` Phil Sainty
2018-08-25 19:11                           ` Richard Stallman
2018-08-25 19:51                             ` Eli Zaretskii
2018-08-26 12:52                               ` hw
2018-08-26 14:43                                 ` Eli Zaretskii
2018-08-27  4:33                                   ` hw
2018-08-27  7:32                                     ` Michael Albinus
2018-08-27 14:35                                       ` hw
2018-08-27 15:29                                         ` Eli Zaretskii
2018-08-27 18:43                                           ` hw
2018-08-28  5:39                                             ` Eli Zaretskii
2018-08-28 20:47                                               ` hw
2018-08-27 15:06                                     ` Eli Zaretskii
2018-08-27 19:46                                       ` hw
2018-08-28  5:38                                         ` Eli Zaretskii
2018-08-28 13:05                                           ` Phil Sainty
2018-08-28 16:50                                             ` Eli Zaretskii
2018-08-28 22:05                                           ` hw
2018-08-29 15:20                                             ` Eli Zaretskii
2018-08-29 20:00                                               ` hw
2018-08-30 13:48                                                 ` Eli Zaretskii
2018-09-01 17:32                                                   ` hw
2018-09-01 18:55                                                     ` Eli Zaretskii
2018-09-02 16:37                                                       ` hw
2018-09-02 17:20                                                         ` Eli Zaretskii
2018-09-01 22:30                                                     ` Drew Adams
2018-09-02 16:43                                                       ` hw
2018-08-30  1:16                                   ` Uday S Reddy
2018-08-30 13:05                                     ` Eli Zaretskii
2018-08-30 21:12                                       ` Uday Reddy
2018-08-31 18:17                                         ` Eli Zaretskii
2018-09-01 17:33                                     ` hw
2018-08-26 20:43                               ` Richard Stallman
2018-08-22 16:24           ` Tom Tromey
2018-08-22 17:40             ` Eli Zaretskii
2018-08-25 16:16               ` Tom Tromey
2018-08-22  7:18         ` martin rudalics
2018-08-22 14:32           ` Eli Zaretskii
2018-08-21 16:17     ` Gemini Lasswell
2018-08-30  0:21 ` Uday Reddy
2018-08-30 13:01   ` 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=87600cukfu.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=emacs-devel@gnu.org \
    --cc=mwd@md5i.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).