Passing messages between ruby thread and scheduling

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)
   def set_value(key, value)
    @champs[key.to_s]= value.to_s

  def initialize()
    @champs =

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

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

  def freeze
    @champs.each { |key, value| value.freeze}

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

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

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