From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur Newsgroups: gmane.lisp.guile.devel Subject: Re: crashes with Fibers Date: Mon, 02 Jul 2018 13:34:37 +0200 Message-ID: <87in5x3m7m.fsf@lassieur.org> References: <8736x63q5v.fsf@lassieur.org> <87sh52j83h.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1530531162 14073 195.159.176.226 (2 Jul 2018 11:32:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 2 Jul 2018 11:32:42 +0000 (UTC) User-Agent: mu4e 1.0; emacs 26.1 Cc: guile-devel@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jul 02 13:32:38 2018 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fZx4Q-0003b3-Bl for guile-devel@m.gmane.org; Mon, 02 Jul 2018 13:32:38 +0200 Original-Received: from localhost ([::1]:60236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZx6X-0005XM-Mn for guile-devel@m.gmane.org; Mon, 02 Jul 2018 07:34:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZx6T-0005XB-3i for guile-devel@gnu.org; Mon, 02 Jul 2018 07:34:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZx6P-0003nT-1Y for guile-devel@gnu.org; Mon, 02 Jul 2018 07:34:45 -0400 Original-Received: from mail.lassieur.org ([83.152.10.219]:60228) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fZx6O-0003mk-Qq; Mon, 02 Jul 2018 07:34:40 -0400 Original-Received: from rodion (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id f1782bef (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); Mon, 2 Jul 2018 11:34:38 +0000 (UTC) In-reply-to: <87sh52j83h.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 83.152.10.219 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19581 Archived-At: Ludovic Court=C3=A8s writes: > Hello Cl=C3=A9ment, > > Cl=C3=A9ment Lassieur skribis: > >> ;; bad >> (define (test4) >> (run-fibers >> (lambda () >> (spawn-fiber >> (lambda () >> (let ((channel (make-channel))) >> (call-with-new-thread >> (lambda () >> (put-message channel "hello world"))))))) >> #:drain? #t)) >> =E2=8A=A3 scheme@(guile-user)> In /home/clement/.guix-profile/share/= guile/site/2.2/fibers/internal.scm: >> 402:6 1 (suspend-current-fiber _) >> In unknown file: >> 0 (scm-error misc-error #f "~A" ("Attempt to suspend fi= ber within continuation barrier") #f) >> ERROR: In procedure scm-error: >> Attempt to suspend fiber within continuation barrier > > I think the problem here is that the new thread inherit the dynamic > environment of the spawning thread. Thus, =E2=80=98put-message=E2=80=99,= called in that > new thread, thinks it=E2=80=99s running within a Fiber, but it=E2=80=99s = not. > > Because of that, =E2=80=98put-message=E2=80=99 tries to suspend itself, b= ut it cannot: > =E2=80=98call-with-new-thread=E2=80=99 is written in C, so it=E2=80=99s a= =E2=80=9Ccontinuation barrier=E2=80=9D > (meaning that it=E2=80=99s a continuation that cannot be captured and res= umed > later.) > > So I think if you really want that, you can perhaps do something like > (untested): > > (call-with-new-thread > (lambda () > (parameterize ((current-fiber #f)) > (put-message channel "hello world")))) It works, but only with (@@ (fibers internal) current-fiber) because the parameter isn't exported. Thank you Ludo!