guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: crashes with Fibers


From: Ludovic Courtès
Subject: Re: crashes with Fibers
Date: Mon, 02 Jul 2018 11:32:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hello Clément,

Clément Lassieur <address@hidden> 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’.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]