topazproject / topaz

A high performance ruby, written in RPython
topazruby.com
BSD 3-Clause "New" or "Revised" License
1k stars 84 forks source link

Implement ThreadLocals #867

Open fniephaus opened 7 years ago

fniephaus commented 7 years ago

Approach is similar to how OSThreadLocals are implemented in Pypy.

Comments are welcome!

eregon commented 7 years ago

Just a note in case it's useful: Thread#[] and #[]= in Ruby can also access "thread-local" variables of other Thread instances (and even set them):

t = Thread.new { Thread.current[:foo] = :bar }.join
t[:foo] # => :bar
fniephaus commented 7 years ago

Interesting, @eregon. I think this should be possible with this approach. However, this PR does not implement the Ruby API yet. That's the next thing to implement. But, @timfel offered to help with that once he is free ;)

fniephaus commented 7 years ago

Please don't merge this just yet as there must be an error in the implementation. Using threads causes a segfault :(

fniephaus commented 7 years ago

Okay, so the segfault is caused by a bug in Pypy's GC. Anyhow, this PR still needs some additional work...