mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add test for thread local variable with fiber.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1ff31c2d2d
commit
cc09ba4699
1 changed files with 35 additions and 0 deletions
|
@ -12,3 +12,38 @@ assert_finish 1, %q{
|
|||
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]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue