ruby-changes:2047
From: ko1@a...
Date: 27 Sep 2007 18:52:25 +0900
Subject: [ruby-changes:2047] akr - Ruby:r13538 (trunk): add test for thread local variable with fiber.
akr 2007-09-27 18:51:24 +0900 (Thu, 27 Sep 2007) New Revision: 13538 Modified files: trunk/bootstraptest/test_knownbug.rb Log: add test for thread local variable with fiber. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=13538&r2=13537 Index: bootstraptest/test_knownbug.rb =================================================================== --- bootstraptest/test_knownbug.rb (revision 13537) +++ bootstraptest/test_knownbug.rb (revision 13538) @@ -12,3 +12,38 @@ sleep 0.1 w.write "a" }, '[ruby-dev:31866]' + +assert_equal "[[nil, 1, 1, nil, nil], [nil, 2, 2, nil]]", %q{ + def tvar(var, val) + old = Thread.current[var] + begin + Thread.current[var] = val + yield + ensure + Thread.current[var] = old + end + end + ary1 = [] + ary2 = [] + fb = Fiber.new { + ary2 << Thread.current[:v] + tvar(:v, 2) { + ary2 << Thread.current[:v] + Fiber.yield + ary2 << Thread.current[:v] + } + ary2 << Thread.current[:v] + Fiber.yield + ary2 << Thread.current[:v] + } + ary1 << Thread.current[:v] + tvar(:v,1) { + ary1 << Thread.current[:v] + fb.resume + ary1 << Thread.current[:v] + } + ary1 << Thread.current[:v] + fb.resume + ary1 << Thread.current[:v] + [ary1, ary2] +} -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml