emacs-devel
[Top][All Lists]
Advanced

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

Re: multi-threaded Emacs


From: Stefan Monnier
Subject: Re: multi-threaded Emacs
Date: Thu, 11 Dec 2008 15:53:07 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

>>> Then any ELisp function that builds on atomics is atomic
>>> itself, presumably (except for macros and other trickery).
SM> No, atomicity does not work that way, sadly.
> "atomic" was a bad word choice on my part.  I meant "safe to put in an
> (atomically) body as you described it."  I think if functions A and B
> are safe, then any function C that only uses A and B is safe too.  Does
> that make more sense?

Yes, that makes sense.  Hopefully, most functions are "safe" in
this respect.

BTW, implementing "atomically" is not necessarily that hard.

Of course, it can be implemented with an "optimistic locking" discipline
where we track changes and undo them if the transaction aborts, but
until we get there, there are meny much simpler implementations which
will be useful.  A first implementation is

  (defmacro atomically (&rest body)
    `(let ((inhibit-thread-switch t))
       ,@body))

A better one, yet still trivial, is

  (defconst the-lock (make-lock))
  (defmacro atomically (&rest body)
    `(progn
       (lock-grab the-lock)
       (unwind-protect
           (progn ,@body)
         (lock-release the-lock))))


-- Stefan




reply via email to

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