Project

General

Profile

Bug #4474 » patch.diff

sorah (Sorah Fukumori), 03/06/2011 10:55 PM

View differences:

lib/pstore.rb
#
def transaction(read_only = false, &block) # :yields: pstore
value = nil
raise PStore::Error, "nested transaction" if @transaction
@lock.synchronize do
raise PStore::Error, "nested transaction" if @transaction
@rdonly = read_only
@transaction = true
@abort = false
test/test_pstore.rb
end
end
end
def test_thread_safe
assert_raise(PStore::Error) do
flag = false
Thread.new do
@pstore.transaction do
@pstore[:foo] = "bar"
flag = true
sleep 1
end
end
until flag; end
@pstore.transaction {}
end
assert_block do
pstore = PStore.new("pstore.tmp2.#{Process.pid}",true)
flag = false
Thread.new do
pstore.transaction do
pstore[:foo] = "bar"
flag = true
sleep 1
end
end
until flag; end
pstore.transaction { pstore[:foo] == "bar" }
File.unlink("pstore.tmp2.#{Process.pid}") rescue nil
end
end
end
(1-1/3)