unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: crashes with Fibers
Date: Mon, 02 Jul 2018 11:32:50 +0200	[thread overview]
Message-ID: <87sh52j83h.fsf@gnu.org> (raw)
In-Reply-To: 8736x63q5v.fsf@lassieur.org

Hello Clément,

Clément Lassieur <clement@lassieur.org> 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))
>     ⊣ 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 fiber 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, ‘put-message’, called in that
new thread, thinks it’s running within a Fiber, but it’s not.

Because of that, ‘put-message’ tries to suspend itself, but it cannot:
‘call-with-new-thread’ is written in C, so it’s a “continuation barrier”
(meaning that it’s a continuation that cannot be captured and resumed
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"))))

HTH!
Ludo’.




  parent reply	other threads:[~2018-07-02  9:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29  9:20 crashes with Fibers Clément Lassieur
2018-07-01 11:16 ` Amirouche Boubekki
2018-07-01 13:09   ` Clément Lassieur
2018-07-01 22:32     ` Amirouche Boubekki
2018-07-01 22:41       ` Amirouche Boubekki
2018-07-01 22:46         ` Amirouche Boubekki
2018-07-02  9:22           ` Clément Lassieur
2018-07-02  9:32 ` Ludovic Courtès [this message]
2018-07-02 11:34   ` Clément Lassieur
2018-07-17 18:16     ` Clément Lassieur
2018-07-19 23:50       ` Amirouche Boubekki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sh52j83h.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).