unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* MPS: which threads need to be registered and how?
@ 2024-07-14 13:00 Eli Zaretskii
  2024-07-14 14:55 ` Gerd Möllmann
  0 siblings, 1 reply; 2+ messages in thread
From: Eli Zaretskii @ 2024-07-14 13:00 UTC (permalink / raw)
  To: Gerd Möllmann, Helmut Eller; +Cc: emacs-devel

The MPS documentation talks about registering threads with MPS.
However, AFAIU this is only needed if a thread either allocates memory
from MPS or accesses memory that is managed by MPS.  Is that correct?

Further, AFAIU memory allocation from MPS is done by calling 'alloc'
in igc.c.  The other memory-allocation functions (xmalloc, xzalloc,
xpalloc, malloc, and all their callers allocate memory from the heap
managed by libc, and MPS does not manage that memory and doesn't need
to know about it.  Is that correct?

The reason I'm asking is that the MS-Windows build of Emacs starts 4
application threads for various purposes.  These are:

  . The I/O thread which handles communications with Windows GUI
    subsystem by exchanging messages with it.  This thread accesses
    some structures of the Lisp machine, most notably the frames'
    list, the frame/window objects, and also some of the variables
    defied via DEFVAR_LISP.  I understand that this thread needs to be
    registered with MPS, is that right?

  . The reader threads started for each sub-process and each network
    or serial connection.  These threads do not allocate any memory,
    and correspond with the main thread via 2 static data structures
    and by using OS synchronization means like critical sections and
    events.  I understand that this thread does NOT need to be
    registered with MPS, is that true?

  . Timer threads used to implement interval timers and profiling.
    There can be at most 2 such threads, and they also communicate
    with the main thread via static structures.  But here there's a
    twist: when the timer expires, the timer thread stops the main
    thread, and then calls the signal handler directly.  SIGALRM
    handler just sets a flag, but SIGPROF handler can call
    record_backtrace, which accesses specpdl.  Does the profiling
    thread need to be registered with MPS?

  . The file-notifications threads.  These allocate memory by calling
    malloc, xmalloc, etc., but doesn't access any MPS-manged memory or
    the Lisp data.  I understand that this thread does NOT need to be
    registered with MPS, is that true?

My other questions are how and when to register a thread and how/when
to deregister it.  I understand that registration is done by calling
mps_thread_reg, but is it okay to call this from the thread function
as its first thing?  And is it okay to deregister a thread just before
it exits, i.e. when the thread function still runs?



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-14 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-14 13:00 MPS: which threads need to be registered and how? Eli Zaretskii
2024-07-14 14:55 ` Gerd Möllmann

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).