[racket] Different mutable vectors for each thread

From: Neil Toronto (neil.toronto at gmail.com)
Date: Sun Jul 15 01:50:52 EDT 2012

To head off wrong answers: It's not thread cells. By themselves, they're 
not enough. Making them "preserved" also isn't the answer.

I'd like a thread-cell-like thing that gives each thread its own mutable 
vector. Here's why thread cells don't work:

#lang racket

(define v (make-thread-cell (vector 0 1)))
(sync (thread (λ () (vector-set! (thread-cell-ref v) 0 6))))
(thread-cell-ref v)


Output:

#<thread>
'#(6 1)


Clearly, both the created thread and the runtime thread access the same 
vector.

Not only do I need this, but I need repeated access to the per-thread 
vectors to be faster than allocating a new one. Ideally, after the first 
access, they'd allocate nothing.

Any ideas?

Neil ⊥

Posted on the users mailing list.