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#70032: 30.0.50; thread-yield inconsistency with macOS GUI and other platforms Date: Wed, 30 Oct 2024 05:50:48 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6811"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: eliz@gnu.org, 70032@debbugs.gnu.org To: Daniel Pettersson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 30 05:52:33 2024 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 1t60h6-0001bp-Ra for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Oct 2024 05:52:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t60gd-0005QL-V8; Wed, 30 Oct 2024 00:52:04 -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 1t60gc-0005QB-73 for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 00:52:02 -0400 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 1t60gb-0002g8-UX for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 00:52:01 -0400 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=uVuXJNkoEyGRmi3p6zIhs7hQA7J4ZiLBWA2eWORVs08=; b=PmGcjo/aojuxe9M0992Zrgaan3ycy+nRh1glIQB45HdbY7lGVyIhygGS8fXKtXv6dLFTmetp9kS07BF8vhw6ylQ9XEsXE/7e+AHS5A80HaQMeqKTzJVoPKzxCDog9VxhZotN7JQaSqEQqZHSEK9U4WePHRidXweJ1nmOOemiw6AfvmD61A0Ts5/ntU9ZQcPwGhaJSytvtIiUwYWDWCy/m98uxPOGczvoxdwh2mQ7FyXcQ6cb969EIFC+r7aQFc0rbebo5cwuFbcssUP6IaI7jYrYXdMME+N1en8TEJIeIaJfw0gu+YrcUR2v4M60EOj26Ugd9HZeGknSxw48RvWoKg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t60gb-0000rt-PK for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 00:52:01 -0400 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: Wed, 30 Oct 2024 04:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70032 X-GNU-PR-Package: emacs Original-Received: via spool by 70032-submit@debbugs.gnu.org id=B70032.17302639193330 (code B ref 70032); Wed, 30 Oct 2024 04:52:01 +0000 Original-Received: (at 70032) by debbugs.gnu.org; 30 Oct 2024 04:51:59 +0000 Original-Received: from localhost ([127.0.0.1]:32959 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t60gZ-0000re-AA for submit@debbugs.gnu.org; Wed, 30 Oct 2024 00:51:59 -0400 Original-Received: from mail-wm1-f48.google.com ([209.85.128.48]:47507) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t60gX-0000rU-LC for 70032@debbugs.gnu.org; Wed, 30 Oct 2024 00:51:58 -0400 Original-Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-431481433bdso59754145e9.3 for <70032@debbugs.gnu.org>; Tue, 29 Oct 2024 21:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730263852; x=1730868652; darn=debbugs.gnu.org; h=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=uVuXJNkoEyGRmi3p6zIhs7hQA7J4ZiLBWA2eWORVs08=; b=eZvrs4rfWQ0SBqOsscSYQjVPmrnyFkuwUnejEjQ7i1NAJ+AWrOQvbQg50B8CP9DqE9 BP3P9T19YxzE1qebYz3AvFUfkctK/z1ncwC2kGCpGOyy49YJvi7pkQD+T+modZZqf8Ah T/04QsARtRZKm5iQvgDf9VzBPxo16vwEyehgWzDYTvEPQabzVuOqBCSVNCQmUjAQ/95s oozCOq352vJ5KlApZZ9vWw8RtL79/Dgtta+LZvJc24aNPEu8su4X6yKLaRXedu3pQ0i2 FCUx/1puM6TFEScvLZJOVq2jJmUHaD1c6+2dlNLM6IQLd9YW3LpuTGYV9FDPraPLo8Cl xrNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730263852; x=1730868652; h=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=uVuXJNkoEyGRmi3p6zIhs7hQA7J4ZiLBWA2eWORVs08=; b=f68q7XAVttYNkrHSs7Or1qbDfj7xejwEIcNLYQOUSKRdgKyNlwGuQg0AWqzq/UQfaq PKhm4Ey3Bt+PShbXN/3AEu2amrMu53ej2QOgU6AbF0M+XCBZj+isQxE5VAG2jW8xuIUX j/K8Hb3uLhHGJwR3zNk0i4Teeh3SqA5+vxUgK6qVMgliB/BydUWdRRDFE6OV3U0vvVa2 NY0emB6+KSl2M+IhvbeX1+GfOcFFYCpyaqCGFWN/a7gqB+OboniuVftZuwaAzCE4szpG V8PHKsEl8u2Fazms5Vkw0xnwTUVDriL4NLFUVLeealQEOTUfeqcUamRLjzQwcYCAK2mm u89g== X-Gm-Message-State: AOJu0Yy2QxFSvL++SUrWOWGbR7IdSvXeO1OhYVF7TVsdb6s9+FmTFu7V 7OYVlniydoQc5YmslA37sx0WCEaXQR9Mnuo+uzgJiTtcdouKS0Ag X-Google-Smtp-Source: AGHT+IEH/Trzt0QynYjS6SmSJ7PHEl97ztzwGIVyYil58Lxu8cN/CGfKrhc2/TT5+Xx3h6toCFmihQ== X-Received: by 2002:a05:600c:1d89:b0:431:53db:3d29 with SMTP id 5b1f17b1804b1-4319acb1026mr95786825e9.18.1730263850893; Tue, 29 Oct 2024 21:50:50 -0700 (PDT) Original-Received: from pro2 (p4fe3a430.dip0.t-ipconnect.de. [79.227.164.48]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd97d5e1sm8989505e9.27.2024.10.29.21.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 21:50:50 -0700 (PDT) In-Reply-To: (Daniel Pettersson's message of "Tue, 29 Oct 2024 21:10:12 +0100") 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:294543 Archived-At: Daniel Pettersson writes: > Now that I am already being a nuisance, I might as well try to resurrect > this bug as well. I have tried to create a patch for this issue, but > failed. I do not understand the internals of emacs threads well enough, > I am happy to try to give it a go but I would require some pointers to > get me started. In bug#72496 I wrote something that I think might be helpful to underwtand how this works in NS. I nowadays build Emacs --without-ns. In GNU Emacs 31.0.50 (build 1, aarch64-apple-darwin23.6.0, NS appkit-2487.70 Version 14.6 (Build 23G80)) of 2024-08-05 built on pro2.fritz.box Repository revision: c7d9cd722e5a7042a52c92f8497f903bfe9870b8 This is one of the problems on macOS that I'm experiencing quite often. I have no idea what is causing this, and I haven't found a way to make it reproducible. I guess I should file a bug report anyway. Let me first try to describe briefly how NS GUI event handling works in Emacs. The whole story starts with get_input_pending which calls gobble_input which calls a terminal's read_socket_hook, which is ns_read_socket in macOS. ns_read_socket calls [NSApplication run] to process macOS GUI events. The problem starts with [NSApplication run] being an endless loop that gets the next event, and dispatches it by calling the application's sendEvent method. The only way to make the run loop terminate is by calling [NSApplication stop]. This sets a flag that [NSApplicatoin run] is supposed to check and then return, so that we eventually return to ns_read_socket. We call [NSApplicaton stop] in our [EmacsApp sendEvent] method. To get there, we post special application-defined events to the application which [NSApplication run] processes and dispatches via sendEvent which calls stop and makes [NSApplication run] return to its caller. Note that stop only sets a flag, so we need to process another event to make run terminate. That's at least my understanding. We are posting these events all over the place, not only before ns_read_socket calls [NSApplication run]. And, to complicate matters, whether or not ns_send_appdefined actually posts an event depends on a global boolean variable. IOW, it's impenetrable. (I'm also leaving out the generation of input_events for Emacs here, which is another can of worms.) Problem is that this not always works. More specifically, this code in ns_read_socket_1 /* Run and wait for events. We must always send one NX_APPDEFINED event to ourself, otherwise [NXApp run] will never exit. */ send_appdefined = YES; ns_send_appdefined (-1); [NSApp run]; gets stuck in the GUI event loop, and the last line never returns. The effect being that Emacs freezes without a beach ball of death. It processes Cocoa events but Emacs never sees any input_events.