unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: hw <hw@adminart.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: psainty@orcon.net.nz, gazally@runbox.com, rms@gnu.org,
	emacs-devel-bounces+psainty=orcon.net.nz@gnu.org,
	emacs-devel@gnu.org
Subject: Re: User interaction from multiple threads
Date: Wed, 29 Aug 2018 00:05:08 +0200	[thread overview]
Message-ID: <87lg8qqh9n.fsf@himinbjorg.adminart.net> (raw)
In-Reply-To: <83mut73vau.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 28 Aug 2018 08:38:17 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: hw <hw@adminart.net>
>> Cc: psainty@orcon.net.nz,  gazally@runbox.com,  rms@gnu.org,  emacs-devel-bounces+psainty=orcon.net.nz@gnu.org,  emacs-devel@gnu.org
>> Date: Mon, 27 Aug 2018 21:46:30 +0200
>> 
>> >> When you don't want threads to have to fight over the mini-buffer, each
>> >> thread needs its own.
>> >
>> > Not necessarily: we could serialize the interactions.
>> 
>> Users still require sequentiality to be able to deal with them.
>
> Yes, but there's no way around that.
>
>> > It doesn't seem to solve the problem: Emacs still has to decide which
>> > minibuffer to use when.  And if you want to put that onus on the user,
>> > then that same user could instead switch to thread N in the single
>> > minibuffer we have now.
>> 
>> true
>> 
>> And if you want neither Emacs to decide which prompts to interrupt the
>> user with, nor let the user decide which prompts to deal with, you're
>> kinda out of options.
>
> I'd prefer Emacs to decide that.

I think Emacs might need at least some help from the user to make the
right decision.

Imagine serializing requests and presenting them to users with the right
amount of sequentiality and historical context was already solved.  What
is Emacs supposed to do with requests after I start using it for
programming and tell it that I am in do-not-disturb-mode?

That mode means that I do not want to be disturbed by any prompt which
is not directly related to what I'm currently doing, i. e. it's ok for
Emacs to ask me for a file name right away when I press C-x C-f.  It is
definitely not ok to prompt me "FOO (y or n)" because Emacs is still
copying or deleting files and wants to know something.  I'd look into
the progress of that some time later, or the next day maybe.

It is also not ok for gnus to change the size of the mini-buffer or to
ask me for a password when it automatically checks for new mail every
now and then.

Since there is no such thing as "a foreground", Emacs has no idea what
I'm doing and no way to decide which requests it may allow to reach me
and which ones not.  It might help if I could qualify them so I can tell
Emacs which classes of requests to allow and which ones not.

Or it needs to queue them all.

> My point above was that having several minibuffers doesn't solve the
> basic problem,

yes, I agree

> which is: how should Emacs decide which of the threads' prompts gets
> submitted to the user at any given time.  When we solve that basic
> problem, we could talk about the details like whether this happens in
> the same minibuffer or in several.

If Emacs shall be allowed to control the users in such a manner, it
should always forward those requests the users want to currently deal
with and withhold the ones they do not want to see :)

How does Emacs figure out what a user currently wants to deal with?  The
user could help Emacs by going into the do-not-disturb-mode and giving
it an adjustment period of, say, 10 seconds.  During these 10 seconds,
the user does nothing, and Emacs does not create any new threads and
does not forward any requests.

After that, Emacs forwards only those requests that have come up after
the adjustment period and have been created by threads that were created
after the adjustment period and, if they were created by other threads,
the threads creating them must not have been created before the
beginning of the adjustment period.

This is probably a retarded idea which sucks, but it is a kind of way,
time based, to figure out what the user is currently doing.  But it
would allow Emacs to prompt me right away for a file name when I want to
visit one, which is what I would want.

While the user is not in do-not-disturb-mode, it doesn't matter which
prompt is forwarded first.  It could be the oldest one, a random one or
the newest one, maybe depending on which the user prefers.

>> > Then the problem becomes how to manage that queue, and which part of
>> > Emacs will do that.  We are back to the same issue, just in a slightly
>> > different form.
>> 
>> Aren't the threads already managed in some way?
>
> No, not really.  There's a single global lock and a race to grab it
> when it becomes released by whatever thread was holding it.

How is being decided for how long the most a thread can stall the
others?  What information is available when a thread is created?

>> The queue would provide the historical context, and the user dealing
>> with queue-entry X would implicitly and transparently switch to
>> thread N.
>
> Placing that onus on the user is indeed one solution, but I still hope
> we could do better.  There are still problems even with such "manual"
> switching: e.g., a background thread will typically run between 2 key
> strokes of user's typing, which could be typing at the prompt of
> another thread.  So a background prompt may request to be serviced in
> the middle of typing a key sequence, and it isn't clear what to do
> then.

hm

Yeah it would suck if was prompted for FOO instead of for a file name
when I wanted to visit a file.

>> >> What you seem to think you must do --- grant an arbitrary thread access
>> >> to the mini-buffer --- is what you *must not* do.
>> >
>> > But in that case everything becomes sequential again, and we gained
>> > nothing by introducing concurrency into Emacs.
>> 
>> The queue circumvents this: it would allow to present sequentiality (by
>> historical context and perhaps by grouping all requests by the operation
>> they are involved with) to the user while the execution of threads can
>> remain serialized.
>
> Maybe I misunderstood what you proposed, but I thought that a request
> gets removed from the queue when its thread finishes its job and
> exits.  If this is indeed what you meant, then we would have lost
> concurrency.

A request would be removed from the queue when it has been served
(answered) by the user.  How would a thread that needs to wait for the
answer finish its job before it has been given the very answer it needs
to finish?

There wouldn't be much point in allowing threads that need to wait for
an answer to stall others.  The others could still run.

>> Emacs could even assume the possible answers to a prompt and perform the
>> actions resulting from the answers in some cases so that when the user
>> makes a decision, the result is already available and the one not needed
>> can be discarded :)
>
> I don't think this is possible in practice.  We usually ask the user
> questions for which only the user knows the answers.

While (query-replace) is waiting for the user to answer its prompt,
Emacs could anticipate the possibility that the user is going to perform
all the possible replacements (after verifying only a few) and create a
version of the buffer in which all replacements have been performed. Now
when the user actually does what Emacs anticipated, it switches the
buffers so the user doesn't need to wait for the replacements to be
performed (assuming that would be faster than doing the replacements,
for the sake of this example).



  parent reply	other threads:[~2018-08-28 22:05 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
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 [this message]
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=87lg8qqh9n.fsf@himinbjorg.adminart.net \
    --to=hw@adminart.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel-bounces+psainty=orcon.net.nz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=gazally@runbox.com \
    --cc=psainty@orcon.net.nz \
    --cc=rms@gnu.org \
    /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).