all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: Eli Zaretskii <eliz@gnu.org>, Tom Tromey <tom@tromey.com>,
	emacs-devel@gnu.org
Subject: Re: Debugging Emacs with threads
Date: Sun, 11 Dec 2016 22:07:11 -0500	[thread overview]
Message-ID: <95672299-F7C8-4E48-B147-43AEF7579A57@raeburn.org> (raw)
In-Reply-To: <87pokyju0j.fsf@linux-m68k.org>


On Dec 11, 2016, at 11:43, Andreas Schwab <schwab@linux-m68k.org> wrote:

> On Dez 11 2016, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> When Emacs stops due to a breakpoint, the thread that is the current
>> one is in sync between GDB and Emacs.  IOW, the current_thread
>> variable describes the same thread on which GDB commands will act.
>> But as soon as you say something like "thread 1" at the GDB prompt,
>> this synchronization is lost: GDB acts on the thread you specified,
>> while current_thread is still pointing at the thread which was the
>> current one when Emacs stopped.
> 
> Why isn't current_thread a thread-local variable?

Multiple C threads can be running at once, but our current model for Lisp is that only one thread runs at a time; current_thread is the indicator of which thread that is, and that’s global to the process.

When we actually decide to start running a different Lisp thread from the “current” one, we need to save the current dynamic state (let bindings, etc) and restore that of the alternate thread.  The thread wanting to “enter” the Lisp environment acquires the global lock, saves the old thread’s state, updates current_thread, restores its own state, and does its business.

This way, threads can release and re-acquire the global lock without having to save and restore all their dynamic state each time, which is a win if we release the lock more often than we actually switch between Lisp threads.

Ken


  parent reply	other threads:[~2016-12-12  3:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-11 16:26 Debugging Emacs with threads Eli Zaretskii
2016-12-11 16:43 ` Andreas Schwab
2016-12-11 17:37   ` Eli Zaretskii
2016-12-11 18:04     ` Andreas Schwab
2016-12-11 18:12       ` Eli Zaretskii
2016-12-12  3:07   ` Ken Raeburn [this message]
2016-12-12  3:18 ` Ken Raeburn
2016-12-12 17:38   ` Eli Zaretskii

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=95672299-F7C8-4E48-B147-43AEF7579A57@raeburn.org \
    --to=raeburn@raeburn.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=schwab@linux-m68k.org \
    --cc=tom@tromey.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.