[plt-scheme] Problem updating variables from threads

From: eliben (eliben at gmail.com)
Date: Mon Oct 22 00:22:29 EDT 2007

Hello,

Consider this code:

(define (parallel-execute . thunks)
  (for-each thread thunks))

(define x 10)

(parallel-execute (lambda () (set! x (* x x)))
                  (lambda () (set! x (+ x 1))))

(display x)

---

Always prints "10", which is surprising, since I would expect either
101 or 121 (given that set! is indeed atomic. otherwise it could be
any of more values, depending on thread switch granularity).

Eli



Posted on the users mailing list.