From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: MPS: which threads need to be registered and how? Date: Sun, 14 Jul 2024 16:00:42 +0300 Message-ID: <864j8sjfgl.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29690"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?iso-8859-1?Q?Gerd_M=F6llmann?= , Helmut Eller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jul 14 15:01:57 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sSyrV-0007YZ-J2 for ged-emacs-devel@m.gmane-mx.org; Sun, 14 Jul 2024 15:01:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSyqn-0005Mf-LM; Sun, 14 Jul 2024 09:01:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSyqk-0005Ia-Jx for emacs-devel@gnu.org; Sun, 14 Jul 2024 09:01:11 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSyqk-0004cN-7y; Sun, 14 Jul 2024 09:01:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:Subject:To:From:Date:in-reply-to: references; bh=cYOln2YmHSuTWFzDqs8QsCe72Fdfa9m8MmYRpFEe88M=; b=mmaR1621VvMpDx ZtCG1M79dw1WWFGetRinLMtgVLgyUmQQ+V8TtQWTe7VhQcG5R4NeGTjVZK4+qW6pR8kR+XNt0Oi50 hBEh6NycYX718BGU967YuAzXy75KX+af+nnF9I1NUEekszN/ZnWinO8xTalVPXLtEFuFCQkJIf+Zg F+rn2VYcLa41ogSF0NprY08zR3B3sCnPsBxo2EqgHSmHiUxDvXFemhI+PISJI8ZjBPbRh4e5N2AjE Mpv+xVlpRS1Jh+3E1QCmb5JIzNH3QaSX5lQb8Sz1NS0xaFSw7UN1A7tyDzFIefeS1r0MCyj1v6Zm8 3O+Z3b8TKahEhdvlYFPA==; X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:321642 Archived-At: 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?