unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs development discussions <emacs-devel@gnu.org>
Subject: Re: advice needed for multi-threading patch
Date: Mon, 28 Sep 2009 20:30:15 -0600	[thread overview]
Message-ID: <m3fxa6h494.fsf@fleche.redhat.com> (raw)
In-Reply-To: <jwvocou8z5c.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 28 Sep 2009 20:27:14 -0400")

Stefan> So what should happen in the following case:
Stefan> Thread A, running in buffer B1, runs the following code:

Stefan>   (let ((default-directory "/foo"))
Stefan>     (with-current-buffer B2 default-directory))

Stefan> You seem to say that it should return "/foo", but currently it returns
Stefan> something else.

I didn't mean to imply that.  I've been too terse, I'll try to expand a
bit more.

First, I think it is clear that the case where there is just a single
thread running should work exactly as elisp does today.  So, the above
will continue to work -- it has to for compatibility.

To this end, I've written a bindings test suite that is on the branch.
It is incomplete but it does test things like the above.  I'm happy to
add any tests you think appropriate to catch more possible problems.
(This is also the one piece that could probably go into trunk
immediately.)

The way ordinary variables work on the branch is, in the base case, just
like current elisp: the value is stored in Lisp_Symbol::value.  Then, if
a thread let-binds the variable, we create a struct Lisp_ThreadLocal.
This has a slot for the global (un-shadowed) value, and also an alist of
thread-local values, keyed by thread.

There are 8 other kinds of variable bindings in Emacs:

* defvaralias.  These work exactly like ordinary bindings, they
  require no change.

* objfwd.  These work exactly as above, because we wrote that "semantic
  patch" to add #defines which indirect through the Lisp_ThreadLocal,
  when needed.

* intfwd
* boolfwd.  These are not done yet.  I think I will write another
  semantic patch to handle these, like we discussed earlier.  Exactly
  what approach I'll use, I don't know... maybe make them exactly like
  objfwd and put a flag bit into Lisp_Objfwd, or keep the same structs
  and change the value's field type.

* buffer-local
* buffer-objfwd.
  Right now each of these has a single conceptual "value" field.
  (Where this is stored and how it is accessed is different in the two
  cases, but that doesn't matter.)  What I propose to do is allow the
  same sort of thread-local indirection where this value is stored, so
  that a buffer-local will have a global value and then a separate
  per-thread value in each thread that has let-bound the variable.
  I wrote the big part of this patch already (adding accessors and
  updating all the C code), all that remains is fixing up symval
  forwarding and whatnot.

* keyboard-local
* frame-local
  I haven't looked into these yet, but I assume we'll end up wanting to
  do the same as buffer-locals.

Stefan> A related case is when a process filter or a sentinel is run via
Stefan> accept-process-output: we'd need to be careful to make sure the
Stefan> code is run in the same thread as the code that called
Stefan> accept-process-output.

Yes, good point.

Tom> There are some oddities implied by making buffer-local let-bindings
Tom> also be thread-specific.  For example, some buffer-locals affect
Tom> redisplay, so what the user sees will depend on the thread in which
Tom> redisplay is run.

Stefan> Redisplay should be run in a completely separate thread (at least
Stefan> conceptually).

Yeah, that would be nice.  I don't know much about redisplay, so I don't
have much idea of how hard this would be, or what problems might arise.

Tom




  parent reply	other threads:[~2009-09-29  2:30 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26  4:38 advice needed for multi-threading patch Tom Tromey
2009-08-26  7:06 ` Ken Raeburn
2009-08-26 14:52   ` Stefan Monnier
2009-08-26 18:50     ` Ken Raeburn
2009-08-27  3:12       ` Stefan Monnier
2009-08-27  6:28         ` Ken Raeburn
2009-08-27 17:02           ` Stefan Monnier
2009-08-26 16:08   ` Tom Tromey
2009-08-26 18:50     ` Ken Raeburn
2009-08-27  5:07       ` Miles Bader
2009-08-27  6:39         ` Ken Raeburn
2009-08-27  6:50           ` Miles Bader
2009-08-28 20:48             ` Juri Linkov
2009-08-28 22:15               ` Miles Bader
2009-08-28 23:27                 ` Juri Linkov
2009-08-28 23:54                   ` Miles Bader
2009-08-29 20:21                 ` Richard Stallman
2009-08-26 15:02 ` Stefan Monnier
2009-08-26 15:31   ` Tom Tromey
2009-08-26 19:18     ` Stefan Monnier
2009-09-18 22:59       ` Tom Tromey
2009-09-19  0:09         ` Stephen J. Turnbull
2009-09-19  0:32         ` Chong Yidong
2009-09-21 21:19         ` Stefan Monnier
2009-09-21 21:50           ` Tom Tromey
2009-09-22 14:24             ` Stefan Monnier
2009-09-22 23:59               ` Ken Raeburn
2009-09-23  3:11                 ` Stefan Monnier
2009-09-23 15:53                 ` Chong Yidong
2009-09-23  3:16               ` Tom Tromey
2009-09-24 17:25                 ` Stefan Monnier
2009-09-24 17:57                   ` Tom Tromey
2009-09-27 20:59                   ` Tom Tromey
2009-09-27 23:05                     ` Stefan Monnier
2009-09-28  4:27                       ` Tom Tromey
2009-09-29  0:27                         ` Stefan Monnier
2009-09-29  2:26                           ` Ken Raeburn
2009-09-29  3:20                             ` Stefan Monnier
2009-09-29  3:57                               ` Ken Raeburn
2009-09-29  3:33                             ` Tom Tromey
2009-09-29  4:07                               ` Ken Raeburn
2009-09-29  2:30                           ` Tom Tromey [this message]
2009-09-23 18:43               ` Giuseppe Scrivano
2009-09-24 17:29                 ` Stefan Monnier
2009-09-24 18:53                   ` Giuseppe Scrivano
2009-09-24 20:04                     ` Tom Tromey
2009-09-24 21:59                       ` Stefan Monnier
2009-09-24 22:23                       ` Giuseppe Scrivano
2009-09-24 22:47                       ` Ken Raeburn
2009-09-28 14:52                       ` Ted Zlatanov
2009-10-05  6:02                       ` joakim
2009-09-28  7:44               ` Lynbech Christian
2009-08-29  0:28 ` Giuseppe Scrivano
2009-08-29  4:57   ` 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=m3fxa6h494.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).