Parameters' initial values

Create issue
Issue #126 resolved
Takashi Kato repo owner created an issue

Parameters created in child thread are not propagated to other thread including parent thread. This is inconvenient.

The following is concrete example

(import (scheme base) (scheme load) (scheme write) (scheme eval) (srfi 18))

(define box (make-vector 1))
(define lock (make-mutex))
(define waiter (make-condition-variable))

(define t 
  (thread-start!
   (make-thread
    (lambda ()
      (mutex-unlock! lock waiter)
      ((vector-ref box 0))))))

(define (do-param v)
  (display (current-thread))
  (display (eval '(*param*) (environment '(param))))
  (eval `(*param* ,v) (environment '(param)))
  (display (eval '(*param*) (environment '(param))))
  (newline))

(thread-join! (thread-start! (make-thread
  (lambda () (do-param ":changed")))))

;; main thread
(do-param ":changed-main")

;; other thread?
(thread-join! (thread-start! (make-thread
  (lambda () (do-param ":changed-other")))))

(vector-set! box 0 (lambda () (do-param ":changed-before")))
(condition-variable-broadcast! waiter)
(thread-join! t)

where (param) is:

(define-library (param)
  (export *param*)
  (import (scheme base))
  (begin
    (define *param* (make-parameter 10))))

Current result

#<thread thread-9 runnable 0x80204320>10:changed
#<thread root runnable 0x8014ce10>#f:changed-main
#<thread thread-10 runnable 0x80204190>:changed-main:changed-other
#<thread thread-7 runnable 0x802044b0>#f:changed-before

Expected result:

#<thread thread-44 runnable 0x80866190>10:changed
#<thread root runnable 0x8014ce10>10:changed-main
#<thread thread-45 runnable 0x80866000>:changed-main:changed-other
#<thread thread-42 runnable 0x80866320>10:changed-before

Comments (1)

  1. Takashi Kato reporter

    Adding global storage for parameter initial values (Fixes #126) This change propagates parameters initial values to other thread even if the parameter is create in child thread.

    → <<cset e07976789c59>>

  2. Log in to comment