unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: John Shahid <jvshahid@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: psainty@orcon.net.nz, gazally@runbox.com, emacs-devel@gnu.org
Subject: Re: User interaction from multiple threads
Date: Thu, 30 Aug 2018 16:15:57 -0400	[thread overview]
Message-ID: <874lfbr4oy.fsf@gmail.com> (raw)
In-Reply-To: <83k1o721qm.fsf@gnu.org>


Eli Zaretskii <eliz@gnu.org> writes:

>> From: John Shahid <jvshahid@gmail.com>
>> Cc: psainty@orcon.net.nz, gazally@runbox.com, emacs-devel@gnu.org
>> Date: Thu, 30 Aug 2018 12:08:32 -0400
>>
>> > I'm afraid there's too much to encapsulate.  E.g., every buffer-local
>> > variable in every buffer to be used by the thread will need to be
>> > encapsulated; and how will the main thread know in advance all that?
>>
>> Why do we need buffer local variables for all the buffers ?
>
> Not all the buffers, only those which the thread function will make
> current at some point.  Surely, you've seen and written code that
> switches buffers as part of doing whatever it needs.

Yeah, but I'm not sure why the portion that is prompting the user should
be switching buffers.  Even in that case the code will look like the
following where all the necessary variables are captured by the closure:

          (on-main-thread
            (read-file-name ...)
            (with-current-buffer other-buffer ;; captured by the closure
              (do-something)
              (read-file-name ..)))


>> Isn't the current buffer during the prompt the only relevant buffer.
>
> No, it is not.  There are also various other parts of the global state
> that should be specific to a thread, like the list of condition-case
> handlers; see the members of 'struct thread_state' as it is defined
> now, for more examples.

I am not sure I totally understand the impact of every field in that
struct has on my proposal.  Speaking of signals, I think those should be
re-emitted on the child thread stack.  For example, the response of the
main thread can indicate the error symbol and data, which can be used in
the child thread to raise/signal again.

>> My idea, is that each thread is started with a pipe which is used to
>> interact with the main thread when it needs to prompt the user.
>
> If you mean literally a pipe, then does this mean you suggest that
> Emacs forks itself and runs each thread in a separate process, talking
> via pipes with other processes?  That's a completely different
> architecture from what we have now, and it wasn't my intent to discuss
> such a complete rewrite of the concurrency code.

No, I am not proposing changing the architecture.  I was proposing to
literally use pipes to communicate between the different threads.  In
fact that doesn't have to be a pipe it could any implementation of a
queue, as was proposed earlier.

> If this is not what you mean, please clarify what you mean by "pipe"
> in this context.
>
>> The child thread write the lambda that needs to run on the main
>> thread then wait for main thread response using
>> `accept-process-output'.  The main thread handles the request in the
>> process filter displaying the prompt and writing the result back to
>> the pipe. Since the child and main thread are sharing the same
>> memory, the communication can simply be the symbol name that holds
>> the closure and the response, respectively.
>
> We already have the async package written by John Wiegley; it sounds
> like you are describing the idea which he already implemented.
>
> The limitation of this is that you need to communicate to much of a
> state to the subordinate Emacs, and some stuff is very hard, sometimes
> impossible, to share this way.

I am proposing something similar but taking advantage of the fact that
threads are sharing the same memory space.  Similar in the sense of
preferring using the existing communication primitives
(e.g. `make-pipe-process' and `accept-process-output').

> In any case, let's stay in the framework of the current basic design
> of how threads work in Emacs.

I sincerely apologize if what I'm being off topic or not helping this
conversation.  This is either due to my inability to explain my thoughts
clearly or my flawed understanding of Emacs internals.  May be trying to
hack together the solution I have in mind will educate me and prove test
the feasibility of this solution.

Thanks,

-js



  reply	other threads:[~2018-08-30 20:15 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 [this message]
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=874lfbr4oy.fsf@gmail.com \
    --to=jvshahid@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=gazally@runbox.com \
    --cc=psainty@orcon.net.nz \
    /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).