[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: crashes with Fibers
From: |
Clément Lassieur |
Subject: |
Re: crashes with Fibers |
Date: |
Tue, 17 Jul 2018 20:16:31 +0200 |
User-agent: |
mu4e 1.0; emacs 26.1 |
Clément Lassieur <address@hidden> writes:
> Ludovic Courtès <address@hidden> writes:
>
>> 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"))))
>
> It works, but only with (@@ (fibers internal) current-fiber) because the
> parameter isn't exported.
>
> Thank you Ludo!
Hi Andy,
I'm adding you to this conversation to notify you about this Fibers
issue. (I don't have a Github account to report the bug there.)
Thanks,
Clément