From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#75275: 30.0.92; `make-thread` bug on macOS 15.2 Date: Thu, 02 Jan 2025 11:04:11 +0100 Message-ID: References: <86bjwplmc1.fsf@gnu.org> <865xmxlivo.fsf@gnu.org> <86y0ztk323.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21101"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 75275@debbugs.gnu.org, alan@idiocy.org, stefankangas@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 02 11:05:27 2025 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1tTI4z-0005B8-Dp for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Jan 2025 11:05:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTI4j-0004N5-MQ; Thu, 02 Jan 2025 05:05:09 -0500 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 1tTI4h-0004LM-C1 for bug-gnu-emacs@gnu.org; Thu, 02 Jan 2025 05:05:07 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tTI4h-0006yZ-38 for bug-gnu-emacs@gnu.org; Thu, 02 Jan 2025 05:05:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=qe0QFBJeaL14qSQ1SxvN5guBqIGlHXEOXrEYN5CHSXk=; b=GFoSefsJ/bbvKEcET8OBdru3e9PaxXoobClL4cxtdxS/c2aAx48bifZUj74BLprdWQs6U8WJtLGnuIHjxHR3A1kiXqQp9OX7JNP2X7j1OxL3S/22bHK/YegerAJcOPkZaTK7PLVlXyODy1xIwAXPCTFP8d0QVh6m7n4n1oniGsD60S5+TUxk+loDoE/ItH0gkbYwPfDcVgFv0mJWgSxVYgTEuVdvmC2yYayWNaFaOqOZCmyrrGvDac18Wofl5DD/1B0AIgh7o+zZa2TffEtTstMzc7LTn2liaGQiNHjRovw3X20yLFaupuN0Q0HsqF3ut7/FMcnW4O3NwvgA0iGGmQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tTI4b-000858-Pv for bug-gnu-emacs@gnu.org; Thu, 02 Jan 2025 05:05:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Jan 2025 10:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75275 X-GNU-PR-Package: emacs Original-Received: via spool by 75275-submit@debbugs.gnu.org id=B75275.173581226331014 (code B ref 75275); Thu, 02 Jan 2025 10:05:01 +0000 Original-Received: (at 75275) by debbugs.gnu.org; 2 Jan 2025 10:04:23 +0000 Original-Received: from localhost ([127.0.0.1]:42798 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tTI3y-000849-Lj for submit@debbugs.gnu.org; Thu, 02 Jan 2025 05:04:23 -0500 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:46153) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1tTI3v-00083u-Ik for 75275@debbugs.gnu.org; Thu, 02 Jan 2025 05:04:21 -0500 Original-Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-aa67333f7d2so1593607166b.0 for <75275@debbugs.gnu.org>; Thu, 02 Jan 2025 02:04:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735812253; x=1736417053; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qe0QFBJeaL14qSQ1SxvN5guBqIGlHXEOXrEYN5CHSXk=; b=KV+gk+0gay32pKXg2NUV+uDPVkmiac5V35CoJFFVp1Lz9rl3MqC9/RwbYT7+J+Nh5W dsfvn6pEYC2qDhhDT6S2ieVx/MebvxqTFpnodu2yIbWVm1j9qN4L/MqhWGWEn+s7mXbl FfTvxzhgIBDNjx2x+sr9ETbRXnHoMQrJ6W0vwc/KwXibEazOOnxcyGOfg1NzAiP8gp9A aVXdXhS1ol5cLL8LV8AN+GwK804iejYIOdiv8eEB6bmFS+lQ2C/ngzlHjMooGj/zSw8o Jk9FQC/ezp4nKEd+G7V3cxwGZzZYFrsd8VgtgRB+h73KfrLNA+fH+Fma3mfF7u4MeUMW Gs/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735812253; x=1736417053; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=qe0QFBJeaL14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Received: by 2002:a17:907:7f88:b0:aa6:3f93:fb99 with SMTP id a640c23a62f3a-aac2d230f1cmr4366387966b.36.1735812252738; Thu, 02 Jan 2025 02:04:12 -0800 (PST) Original-Received: from pro2 (p200300e0b7290d009d701914d6a76d9d.dip0.t-ipconnect.de. [2003:e0:b729:d00:9d70:1914:d6a7:6d9d]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f06da76sm1765157166b.194.2025.01.02.02.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 02:04:12 -0800 (PST) In-Reply-To: <86y0ztk323.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 02 Jan 2025 10:55:32 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:298155 Archived-At: Eli Zaretskii writes: >> From: Gerd M=C3=B6llmann >> Cc: stefankangas@gmail.com, alan@idiocy.org, 75275@debbugs.gnu.org >> Date: Thu, 02 Jan 2025 09:41:38 +0100 >>=20 >> Gerd M=C3=B6llmann writes: >>=20 >> > Eli Zaretskii writes: >> > >> >> So should we add a condition before calling [NSApp run] that we are in >> >> the main thread? >> > >> > ATM, I don't understand how we land in that line in ns_select_1 if not >> > [NSThread isMainThread]. Maybe I need new glasses. I asked Stefan if he >> > can see something in LLDB. >>=20 >> It must something in here: >>=20 >> if (![NSThread isMainThread] >> || (timeout && timeout->tv_sec =3D=3D 0 && timeout->tv_nsec =3D=3D= 0)) >> thread_select (pselect, nfds, readfds, writefds, >> exceptfds, timeout, sigmask); >>=20 >> Should we return here? > > I don't know. Is there anything in the following code that can be > relevant to a non-main thread? Note that non-main threads can > legitimately call wait_reading_process_output, which calls ns_select. > For example, what happens if a non-main Lisp thread starts a > sub-process? we do expect to be able to read the output from that > sub-process. Really hard to tell. Perhaps someone could try to follow what I write below and tell if it makes sense? Everything in ns_select_1. 1. I think this code must run in a non-main thread: if (nr > 0) { pthread_mutex_lock (&select_mutex); ... set some variables ... /* Inform fd_handler that select should be called. */ c =3D 'g'; emacs_write_sig (selfds[1], &c, 1); } selfds is apparently some pipe, NS-specific. The function fd_handler is called when writing to the pipe I assume. fd_handler is set up like this [NSThread detachNewThreadSelector:@selector (fd_handler:) toTarget:NSApp withObject:nil]; Looks to me like it runs in a thread of its own. fd_handler then pselects on the fd sets set in the if above. That looks like it is relevant to reading process output. And that means we may _not_ return from ns_select_1 early when ![NSThread isMainThread]. else if (nr =3D=3D 0 && timeout) { /* No file descriptor, just a timeout, no need to wake fd_handler. */ double time =3D timespectod (*timeout); timed_entry =3D [[NSTimer scheduledTimerWithTimeInterval: time target: NSApp selector: @selector (timeout_handler:) userInfo: 0 repeats: NO] retain]; } 2. This code else if (nr =3D=3D 0 && timeout) { /* No file descriptor, just a timeout, no need to wake fd_handler. */ double time =3D timespectod (*timeout); timed_entry =3D [[NSTimer scheduledTimerWithTimeInterval: time target: NSApp selector: @selector (timeout_handler:) userInfo: 0 repeats: NO] retain]; } means basically only to send an app-defined event after a timeout. I interpret this as "leave the NS event loop to let Emacs do things after a timeout". Looks okay to me. 3. This else /* No timeout and no file descriptors, can this happen? */ { /* Send appdefined so we exit from the loop. */ ns_send_appdefined (-1); } is likely also okay because send_app_defined has code checking for being in the main thread. 4. The [NSApp run] follows, and it can under no circumstances be done in a mon-main thread. We should put that in an if for sure. if ([NSThread isMainThread]) [NSApp run]; 5. The code below is another enigma. I can't figure out why that is done, and what last_appdefined_event_data is for. But since it is run today, I'd propose to just let it run. I don't see that it does immediate harm. :-/