unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
To: Ken Raeburn <raeburn@raeburn.org>
Cc: eliz@gnu.org, rms@gnu.org, emacs-devel@gnu.org
Subject: Re: "concurrency" branch updated
Date: Thu, 05 Nov 2015 15:17:11 +0100	[thread overview]
Message-ID: <877flwv8d4.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <m2y4ech9gm.fsf@newartisans.com> (John Wiegley's message of "Thu,  05 Nov 2015 08:17:13 -0500")

John Wiegley <johnw@newartisans.com> writes:

>>>>>> Ken Raeburn <raeburn@raeburn.org> writes:
>
>>> It seems to me that in Emacs there is no need to be able to switch threads
>>> except when a thread is waiting. That should make things much simpler.
>
>> I think preemptive thread switching (or real concurrent execution) is a
>> better place to wind up, but cooperative thread switching is a good start.
>
> I haven't had a chance to read this entire thread yet, but I wanted to chime
> in and agree with both Richard and Ken. I have relatively few fears about
> cooperative thread switching. Also, it gives us a chance to see how people
> deal with debugging the sorts of issues it can lead to (e.g., a backtrace from
> code unrelated to something you think you just did).
>
> Upgrading to preemptive switching could happen later, once we've had more
> experience with writing cooperative code.

It depends on what "upgrading" means.  For example, Lua offers
"coroutines" which are basically not more than independent stacks but
not parallel execution: the corresponding functions, "yield" and
"resume" both _take_ and _return_ values.  Essentially, this is used as
a control flow mechanism similar to function calls and returns, with the
difference that such "functions" do not lose their place and local
variables when "returning" but continue upon resuming.

Since the switching of threads is accompanied by a passing of values,
executing such threads in parallel is not an option and thus there are
no concurrency issues.

I've used this kind of control flow (basically swapping in a different
stack and returning) in terminal emulators written in assembly language
to good effect: code becomes much more readable if the various code
paths interpreting terminal control sequences can just "call" the user
program for additional characters (where "call" means returning to the
user program and laying dormant until the terminal emulator gets called
with the next character) without losing the place in the logic of the
terminal emulator.

This kind of stack swap is not the same as true multithreading.  It
definitely has interesting applications with regard to things like
generators and streams as it may lead to much more straightforward code
than trying to maintain some internal state in closure variables queried
on reentry when the most natural representation of the internal state
you'd want to maintain is the current instruction and stack pointer.

I think Ada has the concept of "rendezvous" for multithreading where
there are well-defined synchronous parts of interaction as well as
asynchronous execution.

> I hope at that point it would be a fairly seamless upgrade,

For some kinds of control flow application, parallelism might not even
be an option.

-- 
David Kastrup



  reply	other threads:[~2015-11-05 14:17 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-01  6:19 "concurrency" branch updated Ken Raeburn
2015-11-02 17:09 ` Eli Zaretskii
2015-11-02 20:23 ` John Wiegley
2015-11-02 20:35   ` Eli Zaretskii
2015-11-02 20:41     ` Eli Zaretskii
2015-11-02 21:57       ` John Wiegley
2015-11-03  3:58         ` Elias Mårtenson
2015-11-03  9:40           ` Ken Raeburn
2015-11-03 16:26             ` Eli Zaretskii
2015-11-03 16:23           ` Eli Zaretskii
2015-11-03  9:40   ` Ken Raeburn
2015-11-03 11:50     ` other "concurrency" approaches Nic Ferrier
2015-11-03 15:44       ` Eli Zaretskii
2015-11-03 17:16         ` Nic Ferrier
2015-11-03 17:23           ` Eli Zaretskii
2015-11-03 22:28             ` Nic Ferrier
2015-11-04  3:48               ` Eli Zaretskii
2015-11-03 15:14     ` "concurrency" branch updated Filipp Gunbin
2015-11-03 15:35       ` Michael Albinus
2015-11-03 16:38         ` Thierry Volpiatto
2015-11-03 16:29     ` Eli Zaretskii
2015-11-04  9:20       ` Ken Raeburn
2015-11-04 15:40         ` Eli Zaretskii
2015-11-04 19:48           ` Ken Raeburn
2015-11-04 20:51             ` Eli Zaretskii
2015-11-05  5:16               ` Ken Raeburn
2015-11-04 23:09         ` Richard Stallman
2015-11-05  3:41           ` Eli Zaretskii
2015-11-05  6:29           ` Ken Raeburn
2015-11-05 13:17             ` John Wiegley
2015-11-05 14:17               ` David Kastrup [this message]
2015-11-05 15:07                 ` John Wiegley
2015-11-05 21:55               ` Tom Tromey
2015-11-05 22:01                 ` John Wiegley
2015-11-05 22:46             ` Richard Stallman
2015-11-06  8:37               ` Eli Zaretskii
2015-11-05 21:49           ` Tom Tromey
2015-11-05 21:46         ` Tom Tromey
2015-11-06  7:58           ` Eli Zaretskii
2015-11-06 14:58             ` Tom Tromey

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=877flwv8d4.fsf@fencepost.gnu.org \
    --to=dak@gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=raeburn@raeburn.org \
    --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).