From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel Subject: RE: [PATCH] Make get-bytevector-all suspendable. Date: Sun, 16 Jun 2024 15:23:55 +0200 Message-ID: <20240616152355.cDPv2C00V4d9YxY01DPvdv@andre.telenet-ops.be> References: <20230720140103.23221-1-mail@cbaines.net> <87bk4lqb85.fsf@gnu.org> <20240601114041.W9gg2C00G4Gw7VF069ghiP@michel.telenet-ops.be> <87frtddoig.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="_09BBABE8-9D02-4A20-ABFB-10CA895A95D9_" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2343"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "guile-devel@gnu.org" To: =?utf-8?Q?Ludovic_Court=C3=A8s?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sun Jun 16 15:24:27 2024 Return-path: Envelope-to: guile-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 1sIprv-0000QY-6d for guile-devel@m.gmane-mx.org; Sun, 16 Jun 2024 15:24:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sIprc-0007bG-1I; Sun, 16 Jun 2024 09:24:08 -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 1sIpra-0007az-IQ for guile-devel@gnu.org; Sun, 16 Jun 2024 09:24:06 -0400 Original-Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sIprY-0008GV-A5 for guile-devel@gnu.org; Sun, 16 Jun 2024 09:24:06 -0400 Original-Received: from [IPv6:2a02:1811:8c0e:ef00:c1a8:b28e:f81a:fcef] ([IPv6:2a02:1811:8c0e:ef00:c1a8:b28e:f81a:fcef]) by andre.telenet-ops.be with bizsmtp id cDPv2C00V4d9YxY01DPvdv; Sun, 16 Jun 2024 15:23:55 +0200 Importance: normal X-Priority: 3 In-Reply-To: <87frtddoig.fsf@gnu.org> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=telenet.be; s=r24; t=1718544235; bh=/61IMBwYFnj4R849ZfJt7U9pK9ezecaXF/8gt5h4tNs=; h=To:Cc:From:Subject:Date:In-Reply-To:References; b=AQSEmy6mmgffdO6Ot49V0DN2EtnmH85PU6mfcEVxf8h+iMyEov00COa33fzUFafzb uayA8rvFmLceemuWO4yJOsH2AWKeBpRL0aou5KQngDevKdvYhEnuhltOZGPatTw6m9 Jy7SP4h0MMdLWEVhSBGbHFxagHzHReLr7wF6rezOst8oqjh1kGgZuYtfdZfR6dXNNX m+jxgfwDhvdZt3ZjBozvzrWZJt2n5CfmUGwDqJuGF/iDObklNnF2Hb1DoLz7fTpv6l CaVdknQvKtI0s85U936vxpquo8/CxRKJxSKCIYHi43DG8ZCjGHC6dmzGZJ+NrAOKc7 u6R6OwgFsPOsQ== Received-SPF: pass client-ip=2a02:1800:120:4::f00:15; envelope-from=maximedevos@telenet.be; helo=andre.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22444 Archived-At: --_09BBABE8-9D02-4A20-ABFB-10CA895A95D9_ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" >> It currently is difficult to write a correct implementation of get-bytev= ector-all in pure Scheme, because =E2=80=98get-bytevector-all=E2=80=99 need= s to return a _fresh_ bytevector and could return twice (e.g. in case of sy= stem-async-mark + call-with-prompt shenanigans). I think the proposed imple= mentation is incorrect in this way. >Hmm I don=E2=80=99t see how it could return twice. If an async runs while >=E2=80=98get-bytevector-all=E2=80=99 is executed, it cannot cause =E2=80= =98get-bytevector-all=E2=80=99 >to abort to a prompt. I think we=E2=80=99re fine, no? I did not say that =E2=80=98get-bytevector-all=E2=80=99 aborts to a prompt.= Rather, the async itself does the abort-to-prompt, and since the async is = run inside the get-bytevector-all, as a result get-bytevector-all could ret= urn twice (depending on what the handler of call-with-prompt is doing with = the delimited continuation). I=E2=80=99m pretty sure it can do this, that=E2=80=99s how Fibers works (to= be clear I=E2=80=99m referring to the abort-to-prompt from an async, not t= he return twice, Fibers doesn=E2=80=99t do return twice things) -- non-coop= erative scheduling is implemented by aborting from an async. Example (assuming bad/good timing): Thread #1: ;; Consider the situation where the handler invokes the delimited continuat= ion twice. (call-with-prompt [tag + handler things] (lambda () (get-bytevector-all [...])) [tag + handler things]) Thread #2: (system-async-mark (lambda () (abort-to-prompt [tag + more arguments])) [Thread #1])) Best regards, Maxime Devos. --_09BBABE8-9D02-4A20-ABFB-10CA895A95D9_ Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

>&= gt; It currently is difficult to write a correct implementation of get-byte= vector-all in pure Scheme, because =E2=80=98get-bytevector-all=E2=80=99 nee= ds to return a _fresh_ bytevector and could return twice (e.g. in case of s= ystem-async-mark + call-with-prompt shenanigans). I think the proposed impl= ementation is incorrect in this way.

 

>Hmm I don=E2=80=99t see how it could return= twice.=C2=A0 If an async runs while

>=E2=80=98g= et-bytevector-all=E2=80=99 is executed, it cannot cause =E2=80=98get-byteve= ctor-all=E2=80=99

>to abort to a prompt.=C2=A0 I= think we=E2=80=99re fine, no?

 

I did not say that =E2=80=98get-bytevector-all=E2=80= =99 aborts to a prompt. Rather, the async itself does the abort-to-prompt, = and since the async is run inside the get-bytevector-all, as a result get-b= ytevector-all could return twice (depending on what the handler of call-wit= h-prompt is doing with the delimited continuation).

 

I=E2=80=99m pretty sure it can d= o this, that=E2=80=99s how Fibers works (to be clear I=E2=80=99m referring = to the abort-to-prompt from an async, not the return twice, Fibers doesn=E2= =80=99t do return twice things) -- non-cooperative scheduling is implemente= d by aborting from an async.

 

<= p class=3DMsoNormal>Example (assuming bad/good timing):

 

Thread #1:

;; Consider the situation where the handler invokes the delimited co= ntinuation twice.

(call-with-prompt

=C2=A0 [tag + handler things]

=C2=A0 (lamb= da () (get-bytevector-all [...]))

=C2=A0 [tag + han= dler things])

 

Thread #2:

(system-async-mark

=C2=A0 (lambda ()

=C2=A0=C2=A0=C2=A0 (abort= -to-prompt [tag + more arguments]))

=C2=A0[Thread = #1]))

Best regards,

Maxime Devos.

= --_09BBABE8-9D02-4A20-ABFB-10CA895A95D9_--