J
James Edward Gray II
If I launch this server:
#!/usr/local/bin/ruby
require "drb"
require "rinda/tuplespace"
tuplespace = Rinda::TupleSpace.new
DRb.start_service("druby://localhost:61676", tuplespace)
loop do
nums = Array.new(rand(9) + 2) { rand(10) + 1 }
ops = Array.new(nums.size - 1) { %w{+ - * /}[rand(4)] }
problem = nums.zip(ops).flatten.compact.join(" ")
tuplespace.write(["Problem", problem])
puts tuplespace.take(["Result", String]).last
end
__END__
Then run this client:
#!/usr/local/bin/ruby -w
require "drb"
require "rinda/tuplespace"
DRb.start_service
tuplespace = Rinda::TupleSpaceProxy.new(
DRbObject.new_with_uri("druby://localhost:61676")
)
while problem = tuplespace.take(["Problem", %r{^\d+(?: [-+*/] \d+)+$}])
tuplespace.write(["Result", "#{problem.last} = #{eval
problem.last}"])
end
__END__
The client crashes, generally within a few seconds. Adding a sleep
inside the server loop seems to resolve the issue.
Anyone know why?
James Edward Gray II
#!/usr/local/bin/ruby
require "drb"
require "rinda/tuplespace"
tuplespace = Rinda::TupleSpace.new
DRb.start_service("druby://localhost:61676", tuplespace)
loop do
nums = Array.new(rand(9) + 2) { rand(10) + 1 }
ops = Array.new(nums.size - 1) { %w{+ - * /}[rand(4)] }
problem = nums.zip(ops).flatten.compact.join(" ")
tuplespace.write(["Problem", problem])
puts tuplespace.take(["Result", String]).last
end
__END__
Then run this client:
#!/usr/local/bin/ruby -w
require "drb"
require "rinda/tuplespace"
DRb.start_service
tuplespace = Rinda::TupleSpaceProxy.new(
DRbObject.new_with_uri("druby://localhost:61676")
)
while problem = tuplespace.take(["Problem", %r{^\d+(?: [-+*/] \d+)+$}])
tuplespace.write(["Result", "#{problem.last} = #{eval
problem.last}"])
end
__END__
The client crashes, generally within a few seconds. Adding a sleep
inside the server loop seems to resolve the issue.
Anyone know why?
James Edward Gray II