parameterize and thread safety

May 1, 2009 at 9:34 PM

First of all, thanks for your great job.

Not sure if it's an issue, but AFAIK make-parameter should create a thread-local slot, which could be then parameterized.

Here is a simple demonstration of the problem:

(import (rnrs) (ironscheme) (ironscheme clr) (ironscheme threading))

(define param (make-parameter #f))

(define (parameterized-loop n)
(parameterize ((param n)) (let loop () (display (param)) (newline) (thread-sleep 1000) (loop))))

(define (make-parameterized-loop n)
(lambda () (parameterized-loop n)))

(define thr1 (make-thread (make-parameterized-loop 1)))
(define thr2 (make-thread (make-parameterized-loop 2)))

(start-thread thr1)
(start-thread thr2)

It's kind of synthetic, but with-input-from-file/with-output-to-file, for instance, are both using parameterization, as well as some IronScheme's extensions.

MzScheme version works as expected:

#lang scheme
(define param (make-parameter #f))

(define (parameterized-loop n)
(parameterize ((param n)) (let loop () (display (param)) (newline) (sleep 1) (loop))))

(define (make-parameterized-loop n)
(lambda () (parameterized-loop n)))

(thread (make-parameterized-loop 1))
(thread (make-parameterized-loop 2))

Coordinator
May 2, 2009 at 6:52 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
May 2, 2009 at 6:54 AM
Hi amirul

You make a very valid point  :) 

I was not aware of this issue.

I have now fixed it, and it will be checked in shortly.

Thanks

leppie