зеркало из https://github.com/github/ruby.git
Join threads.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
dd20f90408
Коммит
1c01f22d93
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче