Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ruby / usr / share / ri / 2.2.0 / system / Thread / %5b%5d-i.ri
Size: Mime:
U:RDoc::AnyMethod[iI"[]:ETI"Thread#[];TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;	[I"dAttribute Reference---Returns the value of a fiber-local variable (current thread's root fiber ;TI"Pif not explicitly inside a Fiber), using either a symbol or a string name. ;TI"=If the specified variable does not exist, returns +nil+.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim;	[
I"[
;TI"4  Thread.new { Thread.current["name"] = "A" },
;TI"4  Thread.new { Thread.current[:name]  = "B" },
;TI"3  Thread.new { Thread.current["name"] = "C" }
;TI"].each do |th|
;TI"  th.join
;TI"*  puts "#{th.inspect}: #{th[:name]}"
;TI"	end
;T:@format0o;
;	[I"This will produce:;T@o;;	[I"(#<Thread:0x00000002a54220 dead>: A
;TI"(#<Thread:0x00000002a541a8 dead>: B
;TI"(#<Thread:0x00000002a54130 dead>: C
;T;
0o;
;	[
I"DThread#[] and Thread#[]= are not thread-local but fiber-local. ;TI"6This confusion did not exist in Ruby 1.8 because ;TI"/fibers are only available since Ruby 1.9. ;TI"CRuby 1.9 chooses that the methods behaves fiber-local to save ;TI"'following idiom for dynamic scope.;T@o;;	[I"def meth(newvalue)
;TI"
  begin
;TI"*    oldvalue = Thread.current[:name]
;TI"*    Thread.current[:name] = newvalue
;TI"    yield
;TI"  ensure
;TI"*    Thread.current[:name] = oldvalue
;TI"  end
;TI"	end
;T;
0o;
;	[I"MThe idiom may not work as dynamic scope if the methods are thread-local ;TI"&and a given block switches fiber.;T@o;;	[I"f = Fiber.new {
;TI"  meth(1) {
;TI"    Fiber.yield
;TI"	  }
;TI"}
;TI"meth(2) {
;TI"  f.resume
;TI"}
;TI"f.resume
;TI"p Thread.current[:name]
;TI"#=> nil if fiber-local
;TI"N#=> 2 if thread-local (The value 2 is leaked to outside of meth method.)
;T;
0o;
;	[I"EFor thread-local variables, please see #thread_variable_get and ;TI"#thread_variable_set.;T:
@fileI"
thread.c;T:0@omit_headings_from_table_of_contents_below0I"thr[sym]   -> obj or nil
;T0[I"	(p1);T@KFI"Thread;TcRDoc::NormalClass00