Ludovic Courtès <l...@gnu.org> writes:

> Hello Clément,
>
> Clément Lassieur <clem...@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"))))

It works, but only with (@@ (fibers internal) current-fiber) because the
parameter isn't exported.

Thank you Ludo!

Reply via email to