thread question

J

Joe Van Dyk

Every second, a function in the class that's being made available via
DRb should be called automatically. How would I do that?

So I'd have

class Server
def update
# stuff gets updated
end
end

server = DRb.start_service....

server.update() # <== somehow ran every second

DRb.thread.join
 
B

Brian Schröder

Every second, a function in the class that's being made available via
DRb should be called automatically. How would I do that?

So I'd have

class Server
def update
# stuff gets updated
end
end

server = DRb.start_service....

server.update() # <== somehow ran every second

How about:

update_thread = Thread.new(server) do | s |
loop do
sleep 1
s.update
end
end

DRb.thread.join

or is there anything special with drb that prohibits this?

best regards,

Brian
 
J

Joe Van Dyk

How about:

update_thread = Thread.new(server) do | s |
loop do
sleep 1
s.update
end
end


or is there anything special with drb that prohibits this?

I wasn't sure about how the interactions between the threads would
work. I'll try the above and see how it works.
 
B

Brian Schröder

I wasn't sure about how the interactions between the threads would
work. I'll try the above and see how it works.

One difference from your whish is, that this calls the function with a
sleeptime of approximately one second, or sometimes more, and not
every second. Calling it every second is more difficult.

Also, if I remember correctly, ruby threads may be blocked for some
time by some large io activities.

hope to help,

Brian
 
R

Robert Klemme

Brian Schröder said:
One difference from your whish is, that this calls the function with a
sleeptime of approximately one second, or sometimes more, and not
every second. Calling it every second is more difficult.

Also, if I remember correctly, ruby threads may be blocked for some
time by some large io activities.

hope to help,

Another issue worth mentioning is proper synchronization. But since we
don't know anything about the nature of the classes and tasks we could only
speculate. Just in case the OP needs it: have a look at Mutex and Monitor.

Kind regards

robert
 
J

Joe Van Dyk

That's not an issue. It seems to work great. Thanks!
Another issue worth mentioning is proper synchronization. But since we
don't know anything about the nature of the classes and tasks we could only
speculate. Just in case the OP needs it: have a look at Mutex and Monitor.

Syncing's also not an issue. But I'll keep that in mind. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top