now that i've already stuck my foot in my mouth, i'd like to ask a real drb
question.
say you've got a thread accessing an obj which is being served by drb:
require 'drb/drb'
mode = ARGV.shift || 'server'
class Q
def initialize; @q=; end
def push obj; @q << obj; end
def pop; @q.shift; end
end
case mode
when 'server'
q = Q.new
···
#
# is this safe?
#
Thread.new{loop{ sleep 2; q.push Time.now }}
DRb.start_service nil, q
uri = DRb.uri
puts "ruby #{ $0 } client #{ DRb.uri }"
DRb.thread.join
when 'client'
uri = ARGV.shift
DRb.start_service nil, nil
q = DRbObject.new nil, uri
loop do
obj = q.pop
p obj
q.push 42
sleep 0.5
end
end
my understanding is that access to the object via DRb is provided by multiple
synchronized threads. eg. only one DRb thread would be accessing your object
at once so you generally don't need to consider thread coordination. in this
case, however, i have a thread outside of DRb accessing the object - what sort
of coordination would this require? perhaps it would be better to have the
thread obtain a DRbObject itself and allow the DRb library to handle all the
coordination?
eg.
....
when 'server'
q = Q.new
DRb.start_service nil, q
uri = DRb.uri
#
# safe?
#
q = DRbObject.new nil, uri
Thread.new{loop{ sleep 2; q.push Time.now }}
puts "ruby #{ $0 } client #{ DRb.uri }"
DRb.thread.join
....
comments?
-a
--
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it; and a weed grows, even though we do
not love it. --Dogen
===============================================================================