mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
fix Rinda::TupleSpace keeper thread bug.
the thread is started too early. [ruby-talk:264062] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3a0e807df3
commit
135bb57174
3 changed files with 30 additions and 5 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Sun Arg 12 03:56:30 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
|
* lib/rinda/tuplespace.rb: fix Rinda::TupleSpace keeper thread bug.
|
||||||
|
the thread is started too early. [ruby-talk:264062]
|
||||||
|
|
||||||
|
* test/rinda/test_rinda.rb: fix Rinda::TupleSpace keeper thread bug.
|
||||||
|
the thread is started too early. [ruby-talk:264062]
|
||||||
|
|
||||||
Sat Aug 11 07:34:10 2007 Tadayoshi Funaba <tadf@dotrb.org>
|
Sat Aug 11 07:34:10 2007 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* lib/date/format.rb: reverted some wrongly erased "o" options
|
* lib/date/format.rb: reverted some wrongly erased "o" options
|
||||||
|
|
|
@ -449,7 +449,6 @@ module Rinda
|
||||||
|
|
||||||
def write(tuple, sec=nil)
|
def write(tuple, sec=nil)
|
||||||
entry = create_entry(tuple, sec)
|
entry = create_entry(tuple, sec)
|
||||||
start_keeper
|
|
||||||
synchronize do
|
synchronize do
|
||||||
if entry.expired?
|
if entry.expired?
|
||||||
@read_waiter.find_all_template(entry).each do |template|
|
@read_waiter.find_all_template(entry).each do |template|
|
||||||
|
@ -459,6 +458,7 @@ module Rinda
|
||||||
notify_event('delete', entry.value)
|
notify_event('delete', entry.value)
|
||||||
else
|
else
|
||||||
@bag.push(entry)
|
@bag.push(entry)
|
||||||
|
start_keeper if entry.expires
|
||||||
@read_waiter.find_all_template(entry).each do |template|
|
@read_waiter.find_all_template(entry).each do |template|
|
||||||
template.read(tuple)
|
template.read(tuple)
|
||||||
end
|
end
|
||||||
|
@ -484,7 +484,6 @@ module Rinda
|
||||||
def move(port, tuple, sec=nil)
|
def move(port, tuple, sec=nil)
|
||||||
template = WaitTemplateEntry.new(self, tuple, sec)
|
template = WaitTemplateEntry.new(self, tuple, sec)
|
||||||
yield(template) if block_given?
|
yield(template) if block_given?
|
||||||
start_keeper
|
|
||||||
synchronize do
|
synchronize do
|
||||||
entry = @bag.find(template)
|
entry = @bag.find(template)
|
||||||
if entry
|
if entry
|
||||||
|
@ -497,6 +496,7 @@ module Rinda
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@take_waiter.push(template)
|
@take_waiter.push(template)
|
||||||
|
start_keeper if template.expires
|
||||||
while true
|
while true
|
||||||
raise RequestCanceledError if template.canceled?
|
raise RequestCanceledError if template.canceled?
|
||||||
raise RequestExpiredError if template.expired?
|
raise RequestExpiredError if template.expired?
|
||||||
|
@ -521,7 +521,6 @@ module Rinda
|
||||||
def read(tuple, sec=nil)
|
def read(tuple, sec=nil)
|
||||||
template = WaitTemplateEntry.new(self, tuple, sec)
|
template = WaitTemplateEntry.new(self, tuple, sec)
|
||||||
yield(template) if block_given?
|
yield(template) if block_given?
|
||||||
start_keeper
|
|
||||||
synchronize do
|
synchronize do
|
||||||
entry = @bag.find(template)
|
entry = @bag.find(template)
|
||||||
return entry.value if entry
|
return entry.value if entry
|
||||||
|
@ -529,6 +528,7 @@ module Rinda
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@read_waiter.push(template)
|
@read_waiter.push(template)
|
||||||
|
start_keeper if template.expires
|
||||||
template.wait
|
template.wait
|
||||||
raise RequestCanceledError if template.canceled?
|
raise RequestCanceledError if template.canceled?
|
||||||
raise RequestExpiredError if template.expired?
|
raise RequestExpiredError if template.expired?
|
||||||
|
@ -615,8 +615,11 @@ module Rinda
|
||||||
def start_keeper
|
def start_keeper
|
||||||
return if @keeper && @keeper.alive?
|
return if @keeper && @keeper.alive?
|
||||||
@keeper = Thread.new do
|
@keeper = Thread.new do
|
||||||
while need_keeper?
|
while true
|
||||||
keep_clean
|
synchronize do
|
||||||
|
break unless need_keeper?
|
||||||
|
keep_clean
|
||||||
|
end
|
||||||
sleep(@period)
|
sleep(@period)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -240,6 +240,20 @@ module TupleSpaceTestModule
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ruby_talk_264062
|
||||||
|
th = Thread.new { @ts.take([:empty], 1) }
|
||||||
|
sleep 2
|
||||||
|
assert_raises(Rinda::RequestExpiredError) do
|
||||||
|
th.value
|
||||||
|
end
|
||||||
|
|
||||||
|
th = Thread.new { @ts.read([:empty], 1) }
|
||||||
|
sleep 2
|
||||||
|
assert_raises(Rinda::RequestExpiredError) do
|
||||||
|
th.value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_core_01
|
def test_core_01
|
||||||
5.times do |n|
|
5.times do |n|
|
||||||
@ts.write([:req, 2])
|
@ts.write([:req, 2])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue