[plt-scheme] fluid-let and threads
Hi,
I am trying to understand the semantics of fluid-let in the presence
of threads.
First, consider this program:
(define x 1)
(fluid-let ((x 2))
(thread (lambda()
(printf "~a~n" x)
)))
prints a 1, which suggests that a thread created within a fluid-let
does not see the fluid binding. Ok, that's a possibility.
But, it turns to be different if I add a bit of synchronization
between the two threads. First, a variant that gives the same result
(1):
(define x 1)
(define ch (make-channel))
(fluid-let ((x 2))
(thread (lambda()
(printf "~a~n" x)
(channel-put ch 'ok))))
(channel-get ch)
Now, consider I move the channel-get within the fluid-let:
(define x 1)
(define ch (make-channel))
(fluid-let ((x 2))
(thread (lambda()
(printf "~a~n" x)
(channel-put ch 'ok)))
(channel-get ch)
)
I get 2!! meaning the value bound to x in the printf of the created
thread is now 2. Just commenting out the "(channel-get ch)"
expression, and I am back to getting a 1.
Any clarification is more than welcome!
Thank you,
-- Éric, completely puzzled
PS: using DrScheme 372 language MzScheme