mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Join threads.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dd20f90408
commit
1c01f22d93
1 changed files with 14 additions and 6 deletions
|
@ -77,28 +77,36 @@ class PStoreTest < Test::Unit::TestCase
|
|||
def test_thread_safe
|
||||
assert_raise(PStore::Error) do
|
||||
flag = false
|
||||
Thread.new do
|
||||
th = Thread.new do
|
||||
@pstore.transaction do
|
||||
@pstore[:foo] = "bar"
|
||||
flag = true
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
sleep 0.1 until flag
|
||||
@pstore.transaction {}
|
||||
begin
|
||||
sleep 0.1 until flag
|
||||
@pstore.transaction {}
|
||||
ensure
|
||||
th.join
|
||||
end
|
||||
end
|
||||
begin
|
||||
pstore = PStore.new(second_file, true)
|
||||
flag = false
|
||||
Thread.new do
|
||||
th = Thread.new do
|
||||
pstore.transaction do
|
||||
pstore[:foo] = "bar"
|
||||
flag = true
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
sleep 0.1 until flag
|
||||
assert_equal("bar", pstore.transaction { pstore[:foo] })
|
||||
begin
|
||||
sleep 0.1 until flag
|
||||
assert_equal("bar", pstore.transaction { pstore[:foo] })
|
||||
ensure
|
||||
th.join
|
||||
end
|
||||
end
|
||||
ensure
|
||||
File.unlink(second_file) rescue nil
|
||||
|
|
Loading…
Add table
Reference in a new issue