Thread local variables in ruby
September 29th, 2008 • Uncategorized
The following is taken from the Pickaxe
As we described in the previous section, a thread can normally access any variables that are in scope when the thread is created. Variables local to the block of a thread are local to the thread, and are not shared.But what if you need per-thread variables that can be accessed by other threads — including the main thread?
Threadfeatures a special facility that allows thread-local variables to be created and accessed by name. You simply treat the thread object as if it were aHash, writing to elements using[]=and reading them back using[].
Thread.current[:thread_local_var] = :foo Thread.current[:thread_local_var] # prints foo
2 Responses (Add Your Comment)
-
cwxwwwxdfvwwxwx December 25, 2008at 7:53 pm
-
hello it is test. WinRAR provides the full RAR and ZIP file support, can decompress CAB, GZIP, ACE and other archive formats.
tkwgubjwphimuzxuvbpjjrdqhphbpntbdlehello
well, hi admin adn people nice forum indeed. how’s life? hope it’s introduce branch ;)