emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very interesting analysis of "the state of Emacs"


From: Jonathan Rockway
Subject: Re: Very interesting analysis of "the state of Emacs"
Date: Wed, 30 Apr 2008 23:23:03 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

* On Wed, Apr 30 2008, David Hansen wrote:
> There are some small languages that implement this (e.g. Lua or Scheme
> (not in the standard but it's a natural use for continuations)).  The
> main problem I would see is emacs dynamic scope, e.g. what's the value
> of a variable in one thread if another one let binds it.

I don't think let bindings are the problem, it's easy for two
invocations of the same function to have separate dynamic scopes.
Consider:

  (defun foo nil (let (a b c) (bar)))
  (defun bar nil (message "(a %s) (b %s) (c %s)" a b c))
 
If we start two foos in parallel, everything works:

  1:                          2:
  foo                         foo
  let #<scope (a, b, c) 0x1>  let #<scope (a, b, c) 0x2>
  bar (uses scope 0x1)        bar (uses scope 0x2)

Basically, each invocation is logically a separate process.  I don't see
any problems with something like this.  The dynamic scope is not a
show-stopper, anyway.

The issue is when we start putting global variables into the mix:

  (defvar shared 42)
  (defun foo nil (incf shared) (incf shared))
  (defun bar nil (decf shared))

If foo and bar start running at the same time, what does shared end up
being?  Without parallelism, you can guarantee that the output of bar
will always be < the initial value of shared.  But not anymore; if "foo"
happens to run while "bar" is running, that's no longer true.

This is a bad example, but this sort of thing is a big problem.  Perhaps
it can be handled by giving each "thread" a copy of the global VM state.

But of course... what do you do for things that can't be copied, like
buffers or window layouts?  What happens if something like this
executes in parallel:

   A (some-slow-function) (goto-char 42)
   B (save-excursion (goto-char 0) (do-something))

And the execution order happens to be:

  (goto-char 1234)
  A (some-slow-function)
  B (save-excursion (goto-char 0)
  A (goto-char 42)
  B (do-something)
  B )

Where is the point now?  Logically it would be at 42, since the
save-excursion shouldn't have moved it... but the save-excursion sets it
back to the initial value of 1234 when it unwinds.  This makes sense
when you look at the execution order, but that's non-deterministic so it
will never be consistent.

Anyway, hopefully someone has some ideas on what to do here.  I admit I
haven't looked at how sxemacs handles this yet. Maybe we can just deal
with locks?  At least in that case my IMAP mail could download while I
am typing in another buffer :)

Regards,
Jonathan Rockway

-- 
print just => another => perl => hacker => if $,=$"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]