Bug #4474 » patch.diff
| 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
|
||