From: MenTaLguY Date: 2008-01-08T05:29:30+09:00 Subject: Re: Fibers clear thread-specific data? On Mon, 7 Jan 2008 09:34:35 +0900, "Tony Arcieri" wrote: > Is this behavior intentional? > >>> Thread.current[:foo] = :bar > => :bar >>> Fiber.new { p Thread.current[:foo] }.resume > nil > => nil >>> Thread.current[:foo] > => :bar I think so -- a lot of existing code uses thread-specific variables to simulate dynamic scoping, which would break if fibers did not each have their own thread-specific data. > Is there any way for a variable to be thread-specific but accessible to > all fibers in that thread? That's an interesting question. At the moment, the best I can think of is to have a (mutex-protected) weakhash of thread -> data pairs, with lookups cached as thread-specific (really fiber-specific) data. Of course, I've not looked closely at 1.9 Fibers -- it may be possible to migrate them between threads, in which case things get harder. I guess it would be best if we could have separate fiber-local and thread-local data; the main issue is just backwards compatibility. -mental