1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
require "./spec_helper"
# interpreter doesn't support threads yet (#14287)
pending_interpreted describe: Thread do
it "allows passing an argumentless fun to execute" do
a = 0
thread = Thread.new { a = 1; 10 }
thread.join
a.should eq(1)
end
it "raises inside thread and gets it on join" do
thread = Thread.new { raise "OH NO" }
expect_raises Exception, "OH NO" do
thread.join
end
end
it "returns current thread object" do
current = nil
thread = Thread.new { current = Thread.current }
thread.join
current.should be(thread)
current.should_not be(Thread.current)
ensure
# avoids a "GC Warning: Finalization cycle" caused by *current*
# referencing the thread itself, preventing the finalizer to run:
current = nil
end
it "yields the processor" do
done = false
thread = Thread.new do
3.times { Thread.yield }
done = true
end
until done
Thread.yield
end
thread.join
end
it "names the thread" do
Thread.current.name.should be_nil
name = nil
thread = Thread.new(name: "some-name") do
name = Thread.current.name
end
thread.name.should eq("some-name")
thread.join
name.should eq("some-name")
end
end
|