From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: User interaction from multiple threads Date: Thu, 30 Aug 2018 16:10:04 +0300 Message-ID: <83y3co0zmb.fsf@gnu.org> 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> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1535634506 30732 195.159.176.226 (30 Aug 2018 13:08:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 30 Aug 2018 13:08:26 +0000 (UTC) Cc: psainty@orcon.net.nz, gazally@runbox.com, emacs-devel@gnu.org To: John Shahid Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 30 15:08:21 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 1fvMgO-0007tY-V9 for ged-emacs-devel@m.gmane.org; Thu, 30 Aug 2018 15:08:21 +0200 Original-Received: from localhost ([::1]:48902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fvMiV-0003nq-56 for ged-emacs-devel@m.gmane.org; Thu, 30 Aug 2018 09:10:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fvMiO-0003nX-HR for emacs-devel@gnu.org; Thu, 30 Aug 2018 09:10:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fvMiK-0003Aa-Iq for emacs-devel@gnu.org; Thu, 30 Aug 2018 09:10:24 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:46048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fvMiK-0003AW-Fj; Thu, 30 Aug 2018 09:10:20 -0400 Original-Received: from [176.228.60.248] (port=1343 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fvMiK-0007f0-3Y; Thu, 30 Aug 2018 09:10:20 -0400 In-reply-to: <87bm9kr3ad.fsf@gmail.com> (message from John Shahid on Wed, 29 Aug 2018 22:34:02 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e 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:229095 Archived-At: > 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? 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. It creates a thread and then the thread competes for the global lock as all the rest; once a thread grabs the lock, it basically runs disregarding the other threads (except if the Lisp program explicitly calls APIs that synchronize with other threads).