all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Cc: miles@gnu.org, Ted Zlatanov <tzz@lifelogs.com>,
	snogglethorpe@gmail.com, emacs-devel@gnu.org
Subject: Re: Threads in emacs implementation
Date: Mon, 20 Jun 2005 13:48:09 +0200	[thread overview]
Message-ID: <85acll6yh2.fsf@lola.goethe.zz> (raw)
In-Reply-To: <87fyvde30c.fsf@kanga.tapsellferrier.co.uk> (Nic Ferrier's message of "Mon, 20 Jun 2005 11:28:19 +0100")

Nic Ferrier <nferrier@tapsellferrier.co.uk> writes:

> Miles Bader <snogglethorpe@gmail.com> writes:
>
>> On 6/17/05, Ted Zlatanov <tzz@lifelogs.com> wrote:
>>> This will make threads more of a utility than a true built-in, and
>>> threaded code would be written especially for that purpose.
>>
>> Do you know of any applications that require this?  For many purposes,
>> using timers etc. seems to work fairly well already.
>>
>> The main reason I can see for wanting threading is to allow users to
>> continue using Emacs in one window while waiting for another window
>> that's doing something (e.g. Gnus updating over a dialup).  However
>> that level of functionality is hard to implement.
>
> I think that's the problem isn't it? Analysis of what benefit Emacs
> could get from threads. 
>
> We don't need threads for improving GNUs - we just need better async
> protocol implementations. They will come, slowly, but surely.

The problem is that you always have a number of tasks that need to get
tackled one after the other.  And this can always done without threads
or even subroutine calls, by storing all relevant details of the
state, like counters, current point etc and so on and then jumping to
central dispatch points.

It is all the same for a computer.  It isn't for a human.  Subroutines
and stacks are currently in use quite heftily for maintaining the
inner state of some nested tasks pretty much in every programming
language.

Now if you have a data _stream_ passing between two different
computing tasks, then each of those tasks has its own inner states to
keep track of, its own local variables, its wn control structure and
so on.

Yes, you _can_ always explicitly hard-code all of that, but that means
that you'll do so only when avoiding it would be more painful than the
alternatives.

When I was younger, I programmed a terminal emulator for use in a BIOS
of mine, and several other stuff in that area.

Now you have escape sequences for cursor positioning that go something
like ESC [ row, column; or so (don't remember the details).  So what
states can the console output code be in?  Well, it can be after the
escape sequence, it can be in the middle of assembling of the row, it
can be in the middle of assembling the column, stuff like that.  And
there are dozens of sequences like that.

In the end, I programmed this more or less like

basicloop:
cp 1ah
jp nz,noesc
call getchar
cp '[
jp nz,nocursor (actually, this was rather done via a jump table)
call getnumber
cp ',
jnz badsequence
push hl
call getnumber
pop de
cp ';
jnz badsequence
set hl=something*hl + something*de
ld (cursor),hl
jp basicloop
badsequence:
  sound bell
jp basicloop

getnumber:
  ld hl,0
  push hl
  call getchar
  pop hl
  ret if a is not in '0..9
  set hl=10*hl + a-'0
  jmp getnumber

Stuff like that.  And then the tricky thing could all be done in
"getchar".  And getchar just switched from a local stack for the
terminal emulator to the stack of the caller, and returned.

And the console output simply switched from the stack of the caller to
the stack of the terminal emulator, and returned.

The whole "inner state" was maintained all inside of a separate
stack.  This was multithreading in connection with synchronous task
switching, if you so wanted, even though in the 80s those buzzwords
were not all around.

And the purpose was to concentrate the "hard" stuff in very few
locations, and facilitate "natural" programming everywhere else.

And that's what multithreading is about: making conceptually easy
tasks easy to code.  Not merely making them possible to code: you can
always hardcode the inner state maintained by the combination of a
stack and the program counter.

But it is hard, error-prone work.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

  parent reply	other threads:[~2005-06-20 11:48 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-07  2:22 Threads in emacs implementation Denis Bueno
2005-06-07  2:52 ` Miles Bader
2005-06-07  2:59   ` Denis Bueno
2005-06-07  4:26     ` Miles Bader
2005-06-07  5:16 ` Ken Raeburn
2005-06-07 10:37   ` Nic Ferrier
2005-06-08 12:02   ` Richard Stallman
2005-06-08 18:01 ` Magnus Henoch
2005-06-08 19:52   ` Nic Ferrier
2005-06-08 20:23     ` jhd
2005-06-08 20:47       ` Nic Ferrier
2005-06-08 22:50         ` Stefan Monnier
2005-06-08 21:43     ` Magnus Henoch
2005-06-08 22:26       ` Nic Ferrier
2005-06-08 22:34       ` hidden buffers for async (was Re: Threads in emacs implementation) Nic Ferrier
2005-06-08 23:36         ` Miles Bader
2005-06-10  0:13         ` Richard Stallman
2005-06-10  1:15           ` hidden buffers for async Nic Ferrier
2005-06-10  1:32             ` Luc Teirlinck
2005-06-10  1:59               ` Nic Ferrier
2005-06-10 22:37             ` Richard Stallman
2005-06-11 20:26               ` Nic Ferrier
2005-06-11 21:05                 ` Henrik Enberg
2005-06-12 10:30                 ` Richard Stallman
2005-06-12 19:48                   ` Nic Ferrier
2005-06-13 15:03                     ` Richard Stallman
2005-06-12 17:18                 ` Stefan Monnier
2005-06-13  6:03                   ` Juri Linkov
2005-06-09 14:41       ` Threads in emacs implementation Richard Stallman
2005-06-09 14:40   ` Richard Stallman
2005-06-10 19:09     ` Ted Zlatanov
2005-06-11  3:48       ` Masatake YAMATO
2005-06-11 12:18       ` Richard Stallman
2005-06-15 15:59         ` Ted Zlatanov
2005-06-15 23:26           ` Miles Bader
2005-06-16 16:25             ` Ted Zlatanov
2005-06-17  0:56               ` Miles Bader
2005-06-17 14:09                 ` Ted Zlatanov
2005-06-17 18:47                   ` Richard Stallman
2005-06-20 18:04                     ` Ted Zlatanov
2005-06-21 15:13                       ` Richard M. Stallman
2005-06-21 18:36                         ` Nic Ferrier
2005-06-22  3:40                           ` Richard M. Stallman
2005-06-20  2:11                   ` Miles Bader
2005-06-20 10:28                     ` Nic Ferrier
2005-06-20 11:19                       ` Lennart Borgman
2005-06-20 11:48                       ` David Kastrup [this message]
2005-06-20 12:07                         ` Nic Ferrier
2005-06-20 17:52                     ` Ted Zlatanov
  -- strict thread matches above, loose matches on Subject: below --
2005-06-08  8:24 tomas
2005-06-09  0:29 Steven Wu

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85acll6yh2.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    --cc=snogglethorpe@gmail.com \
    --cc=tzz@lifelogs.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.