Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > passing messages between ruby thread and scheduling

Reply
Thread Tools

passing messages between ruby thread and scheduling

 
 
vincent
Guest
Posts: n/a
 
      06-22-2005
Hello, this is my first post on this mailing list!

i am currently trying to code some sort of very basic multi-agent in
ruby (just to
test some idea)

each agent run its own thread, and send message to others with some
sort of mailing system (i actually defined a message class, and uses queues
to be thread safe...)

i am actually asking for some advice on several issue.

1st question
the message is constructed by one agent, wich then ask my "kernel"to
transmit
it to one or multiples other agents (yet other threads). If i just want
to be on the
safe side, i just duplicate everything when the message is transmitted...
however, it is not really very efficient...could i implement some sort
of automatic
duplicate on write (actually using the freezing of the message), or any
other ideas?

here an example definition of a very basic message class without duplication

class Message

def get_value(key)
@champs[key.to_s])
end

def set_value(key, value)
@champs[key.to_s]= value.to_s
end

def initialize()
@champs = Hash.new
end

def dup
msg = Message.new
@champs.each { |key, value| msg.set_value(key, value.dup)}
return msg
end

def to_s
str = "----message----\n"
@champs.each { |key, value| str += "#{key} ===> #{value}\n" unless
key == "binary"}
str += "---------------"
end

def freeze
@champs.each { |key, value| value.freeze}
@champs.freeze
super()
end
end

this example will (i think) simply raise an exception if an agent try to
alter
anything in a message frozen (i freeze them in the "kernel", just before
dispatching
them...)


2nd question
is there some simple ways to do scheduling with the agent/threads,
particularly
is there a way to get some sort of information on cpu/memory consumed by
one
thread/agent

i have a lot more other questions (particularly on runtime class/code
creation),
but lets begin with the more basic stuff


Thanks,

vincent



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Condition variables and thread scheduling Alex Young Ruby 2 11-29-2010 11:37 AM
thread scheduling Mark Volkmann Ruby 5 01-11-2006 04:29 PM
Thread for scheduling csjasnoch@wisc.edu Ruby 1 09-02-2005 11:40 PM
weird delay of UDP server (seems to be thread-scheduling issue) chris guenther Ruby 0 04-10-2005 06:21 PM
ASP Thread Scheduling Anomalies Tony Proctor ASP General 6 03-16-2005 04:59 PM



Advertisments