From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Shahid Newsgroups: gmane.emacs.devel Subject: Re: User interaction from multiple threads Date: Thu, 30 Aug 2018 12:08:32 -0400 Message-ID: <875zzrrg5b.fsf@gmail.com> References: <838t59j821.fsf@gnu.org> <87lg92q7ih.fsf@runbox.com> <87bm9xqg46.fsf@runbox.com> <838t51dl10.fsf@gnu.org> <87efehqdlv.fsf@gmail.com> <3c3e954d-65fc-58e6-9165-1c775ead69a2@orcon.net.nz> <87bm9kr3ad.fsf@gmail.com> <83y3co0zmb.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1535645215 3094 195.159.176.226 (30 Aug 2018 16:06:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 30 Aug 2018 16:06:55 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 27.0.50 Cc: psainty@orcon.net.nz, gazally@runbox.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 30 18:06:51 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fvPT8-0000gv-Vb for ged-emacs-devel@m.gmane.org; Thu, 30 Aug 2018 18:06:51 +0200 Original-Received: from localhost ([::1]:49747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fvPVE-0002F7-KV for ged-emacs-devel@m.gmane.org; Thu, 30 Aug 2018 12:09:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fvPUy-0002CU-Lz for emacs-devel@gnu.org; Thu, 30 Aug 2018 12:08:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fvPUt-0007Ed-Qj for emacs-devel@gnu.org; Thu, 30 Aug 2018 12:08:44 -0400 Original-Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:36202) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fvPUt-0007Df-Jl; Thu, 30 Aug 2018 12:08:39 -0400 Original-Received: by mail-qt0-x242.google.com with SMTP id t5-v6so10776145qtn.3; Thu, 30 Aug 2018 09:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=Zhp1BoDIUN1Z/byiLx8Tqta3rstCSdNm63pDF+j4Gck=; b=hWfhg5XlM/qLSeezsjafrD49F0MCi9P6AykmgTu+UoaNootcBi8p8u7DsvKhG/DzqM Tn7viXKEK66aPViBUrPelxEPraPTpVJH2sbKmVRc56pVNnACfYYkn0TSikkrlK5oLaNT taUtlIah8jXAVeRHm1noK+ROyseLFWh1KFME/22ugCKbwu7uXvK97s8gtdlFuP0drXRS /NmVOpKGHlRCatMraHFgcVolqVqCMx/ij7crg5G3ngccrR77HALrbSa+/bzBm1lWh4yx jMW572DDQIUBp6u4a3yRpX+1Kx5SsXg42Chu4mLmhnnabV8twI0bRT8spxBZdr+J3yx/ GuAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=Zhp1BoDIUN1Z/byiLx8Tqta3rstCSdNm63pDF+j4Gck=; b=AAkEaaRPZ1sAJrWdBT1X0LwOdM/OpioRpF9eI/2V4LMoiEUXufmkhoQiPmC0TwQwTU xQdQnqJquGRuQA6W8ep6ZYrkvf6YPb1X55A7psO31iJTe+tFLO9VYlw0h47G6gOmZ8Q3 VpzaSeS0wB3BrBCYzZpZLd6rW0xZtK3WfBbx9FTsCW70EthdapCKJQ3umPmyBtFdYbIV 2h+iAwxJBGHHkfHCIclJTuNvx6+Wyip1s9fXTLqltTo0qu2I13Y2eP8U9YA4p1zQNr3c XfN9ZJNTEKPY4u2VRtLqFOk0O/X8z48brpxl6bJIwbVzszKzgABV5WY8T+uF0l9AMRpp cxeQ== X-Gm-Message-State: APzg51Br2cG6+E4FrIvUD2xIAApV9fUe2WC4/2eDgSfkyaTj/i+nKjoG x/CRiSp1dfL7X85Lo1NuxDYkXWNF X-Google-Smtp-Source: ANB0VdbfjnJDuPhdTybX+A+elO+b5bkqx5IF16V+x9fyhCT+tmwG+XMqos8sHlAXFL9eUQUNvetWhQ== X-Received: by 2002:a37:b402:: with SMTP id d2-v6mr7185426qkf.234.1535645317751; Thu, 30 Aug 2018 09:08:37 -0700 (PDT) Original-Received: from amun (cpe-104-162-86-217.nyc.res.rr.com. [104.162.86.217]) by smtp.gmail.com with ESMTPSA id m12-v6sm4232230qkl.54.2018.08.30.09.08.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 09:08:37 -0700 (PDT) In-reply-to: <83y3co0zmb.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:229105 Archived-At: Eli Zaretskii writes: >> From: John Shahid >> Cc: Eli Zaretskii , Gemini Lasswell , emacs-devel@gnu.org >> Date: Wed, 29 Aug 2018 22:34:02 -0400 >> >> > The notion of user interaction all happening on the main thread was >> > proposed earlier, and it was pointed out that it's very difficult to >> > do that, because the user interaction may involve arbitrary data which >> > is local to the originating thread. >> >> I thought closures would solve such a problem by encapsulating the >> context. I imagine the main thread receiving forms from other threads >> evaluating them and returning the results back to the thread which >> becomes the value of the `(on-main-thread ...)`. What did I miss ? > > 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 ? Isn't the current buffer during the prompt the only relevant buffer. I was thinking that the `(on-main-thread ...)` macro (or whatever it ends up being called) can expand to something like the following: (execute-on-main-thread (let ((buf (current-buffer))) (lambda () (with-current-buffer buf body)))) > And I think your mental model of how threads work in Emacs is > inaccurate: the main thread doesn't dispatch the other threads, in the > sense of controlling them and interacting with them. I know, I am proposing to change that but not in a very intrusive way. 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. 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. Hope this clarifies my idea. Happy to hear your thoughts.