Hello,

I've been experimenting with guile-fibers.  I noticed that
`with-parameters*' procedure included as an "extra" in Guile's srfi-39
creates a continuation barrier.  From the documentation it is not clear
that it does so.

Consider this sample program (which I ran with Guile 3.0.9 and Fibers
1.0.0, as they are defined in Guix
2fda889ac992977af7b4cd96d09f737d834e0b2d):

--8<---------------cut here---------------start------------->8---
(use-modules (fibers)
             (fibers channels)
             (srfi srfi-18)
             ((srfi srfi-39) #:select (with-parameters*)))

(define %my-channel
  (make-channel))

(define %my-param
  (make-parameter #f))

(define %my-thread
  (make-thread (lambda ()
                 (run-fibers (lambda ()
                               (with-parameters* (list %my-param) '(hello)
                                 (lambda ()
                                   (put-message %my-channel (%my-param))
                                   'ok)))))))

(thread-start! %my-thread)

(format #t "message: ~a~%" (get-message %my-channel))

(thread-join! %my-thread)
--8<---------------cut here---------------end--------------->8---

It prints:

> Uncaught exception in task:
> In fibers.scm:
>    186:20  6 (_)
>    145:21  5 (_)
> In unknown file:
>            4 (with-fluids* (#<fluid 7f192cf70d70>) (hello) #<procedure 
> 100903e0 at <…>)
> In current input:
>     17:35  3 (_)
> In fibers/operations.scm:
>    154:10  2 (perform-operation _)
> In fibers/scheduler.scm:
>     357:6  1 (suspend-current-task _)
> In ice-9/boot-9.scm:
>   1685:16  0 (raise-exception _ #:continuable? _)
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> Attempt to suspend fiber within continuation barrier

But if I use `parameterize' rather than `with-parameters*', no errors
occur.  Here's an example of a working program:

--8<---------------cut here---------------start------------->8---
(use-modules (fibers)
             (fibers channels)
             (srfi srfi-18))

(define %my-channel
  (make-channel))

(define %my-param
  (make-parameter #f))

(define %my-thread
  (make-thread (lambda ()
                 (run-fibers (lambda ()
                               (parameterize ((%my-param 'hello))
                                 (put-message %my-channel (%my-param))
                                 'ok))))))

(thread-start! %my-thread)

(format #t "message: ~a~%" (get-message %my-channel))

(thread-join! %my-thread)
--8<---------------cut here---------------end--------------->8---

It prints:

> message: hello

Is it a bug that `with-parameters*' doesn't work equivalently?  Or am I
reading the info pages wrong?

Best :)
Wojtek

--
W. Kosior

website: https://koszko.org/koszko.html
fediverse: https://friendica.me/profile/koszko/profile
PGP fingerprint: E972 7060 E3C5 637C 8A4F  4B42 4BC5 221C 5A79 FD1A

Attachment: pgpB39yaIbqiW.pgp
Description: OpenPGP digital signature

Reply via email to