From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrew Tropin via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#72095: Non-local exit with thunk from system-async-mark doesn't restore asyncs block level Date: Sat, 13 Jul 2024 20:16:21 +0400 Message-ID: <87o7716ze2.fsf@trop.in> References: <871qe8fj68.fsf@trop.in> Reply-To: Andrew Tropin Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34123"; mail-complaints-to="usenet@ciao.gmane.io" To: 72095@debbugs.gnu.org, wingo@pobox.com, ludo@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sat Jul 13 18:17:22 2024 Return-path: Envelope-to: guile-bugs@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 1sSfR2-0008eT-Vm for guile-bugs@m.gmane-mx.org; Sat, 13 Jul 2024 18:17:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSfQl-0004XY-TM; Sat, 13 Jul 2024 12:17:03 -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 1sSfQj-0004XL-Rp for bug-guile@gnu.org; Sat, 13 Jul 2024 12:17: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 1sSfQj-0008Tv-JS for bug-guile@gnu.org; Sat, 13 Jul 2024 12:17:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sSfQk-0005rz-6N for bug-guile@gnu.org; Sat, 13 Jul 2024 12:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 13 Jul 2024 16:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72095 X-GNU-PR-Package: guile X-Debbugs-Original-To: bug-guile@gnu.org, Andy Wingo , Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Received: via spool by submit@debbugs.gnu.org id=B.172088739822526 (code B ref -1); Sat, 13 Jul 2024 16:17:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Jul 2024 16:16:38 +0000 Original-Received: from localhost ([127.0.0.1]:56624 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sSfQM-0005rG-EN for submit@debbugs.gnu.org; Sat, 13 Jul 2024 12:16:38 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:37186) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sSfQJ-0005r8-TO for submit@debbugs.gnu.org; Sat, 13 Jul 2024 12:16:37 -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 1sSfQI-0004R6-Gm for bug-guile@gnu.org; Sat, 13 Jul 2024 12:16:34 -0400 Original-Received: from out-175.mta1.migadu.com ([2001:41d0:203:375::af]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSfQE-0008Pa-KZ for bug-guile@gnu.org; Sat, 13 Jul 2024 12:16:34 -0400 X-Envelope-To: bug-guile@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=key1; t=1720887386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: references:references; bh=rYvXXDfF8T9CC47lv/aEVfIEpa32Bh8N89BXVpG5GSY=; b=mdjIcc+QHJBREQ0LLPtJXdztPofjbZ0Os00PoYfnebVzCuFnZ0c5CxKCIKCWLIMoMeTq+X 3QJyah7OhJ0gNhI9BjPxl3DcA40OD6Lbe7q6YcFSkn5+Ymcu/RIwMZil1xr93G7f7Xquju No5TFbt7Yef0CJ26FsGxvAI2+8aghgcj0elIm1wVJod2HUprgMmPqE4oa1FebEelAyKfEp DDO/iJbe0MTY4zn1zs6U/fHfeyen5HU7kVfR5LfusVelVvGchuNV/K0BHeT9tlsqmHxteG 80NTOkn558PY4sQbaSL2HSi+kvmjTulHszq0udWNg1uh2QmZVKRxWB7YszYJCg== X-Envelope-To: wingo@pobox.com X-Envelope-To: ludo@gnu.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:203:375::af; envelope-from=andrew@trop.in; helo=out-175.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10899 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable TLDR: abort-to-prompt restores asyncs block level. abort-to-prompt from a procedure scheduled with system-async-mark doesn't restore asyncs block level. Some more context: I was trying to implement interruptible and reusable threads on top of delimited continuations and asynchronous interrupts. The interruption of evaluation is implemented simply by aborting to prompt by procedure scheduled with system-async-mark. It works fine. The problem is that there is a short moment of time when we are outside of prompt and if someone will try to abort to prompt it will fail. To prevent this, the prompt setup routine is done in the context, where asyncs are blocked, after prompt is set we can run a thunk in context with unblocked asyncs (so it can be interrupted). So this was a plan, but unfortunatelly if abort-to-prompt is done by a procedure scheduled by system-async-mark the asyncs are not re-blocked and thus next attempt to unblock asyncs fails with exception. I have an idea on how to workaround my use case, but it seems that non-local escape in procedures scheduled by system-async-mark doesn't re-block asyncs is potentially a bug. Here is a simplified reproducer of the problem: =2D-8<---------------cut here---------------start------------->8--- (begin (use-modules (ice-9 threads)) (define prompt-tag (make-prompt-tag 'tmp)) (define (blocked-async-loop) (call-with-blocked-asyncs (lambda () (let loop ((i 0)) (format #t "\nstep: ~a\n" i) (format #t "--->\n") (call-with-prompt prompt-tag (lambda () (format #t "++++ inside prompt\n" i) (call-with-unblocked-asyncs (lambda () (format #t "++++ inside unblocked async\n" i) ;; This jump works fine. Async get re-blocked (abort-to-prompt prompt-tag 'from-inside-loop)))) (lambda (k . args) (format #t "=3D=3D=3D=3D jumped out of prompt: ~a\n" args))) (format #t "<---\n") (sleep 2) (when (< i 5) (loop (1+ i))))))) (let* ((th (call-with-new-thread (lambda () (blocked-async-loop))))) (sleep 3) (system-async-mark (lambda () ;; This jump doesn't lead to re-blocking asyncs (abort-to-prompt prompt-tag 'from-async-mark)) th) (sleep 8))) =2D-8<---------------cut here---------------end--------------->8--- The output is following: =2D-8<---------------cut here---------------start------------->8--- step: 0 =2D--> ++++ inside prompt ++++ inside unblocked async =3D=3D=3D=3D jumped out of prompt: (from-inside-loop) <--- step: 1 =2D--> ++++ inside prompt ++++ inside unblocked async =3D=3D=3D=3D jumped out of prompt: (from-inside-loop) <--- step: 2 =2D--> ++++ inside prompt =3D=3D=3D=3D jumped out of prompt: (from-async-mark) <--- step: 3 =2D--> ++++ inside prompt 3 (call-with-blocked-asyncs #) In /data/abcdw/work/abcdw/guile-ares-rs/dev/guile/2024-07-13-async-mark-blo= ck.scm: 18:12 2 (_) In unknown file: 1 (call-with-unblocked-asyncs #) In ice-9/boot-9.scm: 1676:22 0 (raise-exception _ #:continuable? _) ice-9/boot-9.scm:1676:22: In procedure raise-exception: In procedure call-with-unblocked-asyncs: asyncs already unblocked =2D-8<---------------cut here---------------end--------------->8--- Similiar report: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D48566 =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIyBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmaSqFUACgkQIgjSCVjB 3rB2BA/3W+Jrea6F8Zc979dgU94mkDmDrG3svfbuJLvDFEI/ZOtR9reHA/grpR24 brda3zOCEJurYDgHYvrTmvq5wjz5u3FKiFwVG9DWKx/VUPKXv0T7rN3ZxJMrwIfr I8MeJcvG7lgteZhBcn0lsR0PuQYKYjPkdIOOVtlZb75lyqxRyRKwdVu8ZfmCewbG mkgxc296zaYokarT6AuSWZNudxc8NiIP6Az1bBxCzDZop5ZyQf5ujNPSkJ8nS5eU m6yYCxsJyyjpsw+jhWvEXTD+howZ7lIXncABwUOzjDBaY/SnyXUUe6UsyVrdkQet yzpA/DJ/xglbCwkJJeoMPAiV+zC0eRz2aT3uIHBJT2fZu3sJzFWjw5tO2Z7BFQU5 YG8d9C+Iif9qTN1yS2XcaEcxyD1xDOtkdgHpqh56Ocw8NPc4v3AMzowl+uT4CXr7 7z/5cy6edFvLFaTTPhKez3gIfz68lRo6xwNWeR1HWMInu4MRvKZ2ucVTfWv59r4w 1QNzSlAyQfibF31C4gKJGUGz2WTV3ReZjdmtf4WGxpj6EoIYsgM4Z1TRCTOOtcS+ 9IBrIr3mjGS9ECtKS3Lv2OuAMvNo+J0uVGG17m82ZBYrZ4i7dOrmzmEEy32uLXtQ zhwSCiwYfJ28bxh+11kfE8mgvgcYaVswoH1Ggm3VViRiIDtEWA== =H3ou -----END PGP SIGNATURE----- --=-=-=--