Michael Sperber scripsit:
> OK, thanks. Now, this is different from SRFI 39, where a parameter is
> bound to a single storage cell. Presumably, the spec could be twisted
> to allow thread creation to create new storage cells, but I believe
> this was specifically not the intent of SRFI 39.
Diffidently I suggest that perhaps you remember the history too well
and the final spec not well enough. As written SRFI 39 makes no
references (and deliberately so) to threads. It defines the behavior
for single-threaded Schemes only, and is consistent with any of these
multi-threaded behaviors:
1) share dynamic state among all threads
2) clone dynamic state when a new thread is made
3) give each new thread a fresh dynamic state
I wrote the following bit of code to probe the behavior of various
Schemes:
(require-extension (srfi 18))
(require-extension (srfi 39))
(define hat (make-parameter 'new))
(define (black-hat) (hat 'black))
(define (white-hat) (hat 'white))
(define (print-hat guy)
(display guy) (display " guy, ")
(display (hat)) (display " hat")
(newline))
(define (bad-guy) (print-hat 'bad) (black-hat) (print-hat 'bad))
(print-hat 'good)
(white-hat)
(print-hat 'good)
(thread-join! (thread-start! (make-thread bad-guy)))
(print-hat 'good)
(Note that since the thread is joined immediately after it is started,
the concurrency is entirely deterministic; I'm assuming that no Scheme
is smart enough to figure this out.)
I ran it on Chicken, a type 2 (cloning) system, and got the following
(Felix is on record that both type 1 and type 3 systems are deeply
flawed, but that's just him):
good guy, new hat
good guy, white hat
bad guy, white hat
bad guy, black hat
good guy, white hat
Presumably a type 1 (sharing) system would report the good guy as wearing
a black hat in the fifth line of output, and a type 3 (refreshing)
system would report the bad guy as wearing a new hat in the third line.
--
John Cowan http://ccil.org/~cowan cowan_at_ccil.org
In might the Feanorians / that swore the unforgotten oath
brought war into Arvernien / with burning and with broken troth.
and Elwing from her fastness dim / then cast her in the waters wide,
but like a mew was swiftly borne, / uplifted o'er the roaring tide.
--the Earendillinwe
Received on Sat Feb 10 2007 - 13:08:13 UTC