From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Ludovic_Court=C3=A8s?= Newsgroups: gmane.lisp.guile.devel Subject: Re: Send scheme procedure as callback to foreign thread. Date: Wed, 12 Oct 2022 22:54:18 +0200 Message-ID: <87r0zcu5j9.fsf@gnu.org> References: <86zge2lv5w.fsf@163.com> 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="15826"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) Cc: guile-devel@gnu.org To: Zhu Zihao Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Wed Oct 12 22:54:38 2022 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 1oiikP-0003zj-Vn for guile-devel@m.gmane-mx.org; Wed, 12 Oct 2022 22:54:38 +0200 Original-Received: from localhost ([::1]:42806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiikO-0001s4-Uu for guile-devel@m.gmane-mx.org; Wed, 12 Oct 2022 16:54:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiik9-0001rv-B3 for guile-devel@gnu.org; Wed, 12 Oct 2022 16:54:21 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:55950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiik8-0007DS-PI; Wed, 12 Oct 2022 16:54:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=jZqvhbmZljxCZXuhlTDHvKmngclQO6g+fjWMmi163UQ=; b=pR1QE5vzX8o36iJ4fc+x d/snRiCAFWgFUMaysi5mVuEWb2mKW1T4z7AQhb6z117dbrCtPcZUJGipY9bpGpFL8XMLpuAoo1FZv obZF2KGPdlPSAAuO/AESyKVUodXRv9Oj1yqeQqJkyWanH/YqTU0RtwH3OuQUZVeyaaFgB4y1f69S1 rrTb0fcrg0bPZXpoFhoCQG9YSJ0psemJTLpSpcnvF6ddFMJsFAVRV5tAEfLH93b7Gs6TZIQVsP/68 P/humklcbNo0VxYBuvG6iiSTrebodKW89SjFBSddei4+VQj0oeG6j/V363LdIGd8YSYU+HLDaHiW8 l6gyKk8Al495hw==; Original-Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:56259 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiik8-0005LU-8n; Wed, 12 Oct 2022 16:54:20 -0400 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Primidi 21 =?utf-8?Q?Vend=C3=A9miaire?= an 231 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du Chanvre X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu In-Reply-To: <86zge2lv5w.fsf@163.com> (Zhu Zihao's message of "Tue, 11 Oct 2022 14:37:01 +0800") 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" Xref: news.gmane.io gmane.lisp.guile.devel:21412 Archived-At: Hi, Zhu Zihao skribis: > In Guile FFI programming, we have procedure->pointer, which makes a > Scheme procedure a foreign callback. And foreign library call use this > callback. > > However, if this callback is called in a another foreign thread. The sche= me > context is not properly setup, It may cause crash or UB. > > IIUC, the procedure invoker "invoke_closure" defined in foreign.c > doesn't use scm_with_guile. If we use scm_with_guile to make a foreign > callback, would it be OK to execute Scheme procedure in multithreading co= ntext? Yes, it should be. Could you come up with a minimal reproducer and maybe even a fix, now that you likely found the solution? :-) Thanks in advance, Ludo=E2=80=99. PS: It may be best to use bug-guile to reduce the chances that the issue gets lost.