passing messages between ruby thread and scheduling

Discussion in 'Ruby' started by vincent, Jun 22, 2005.

  1. vincent

    vincent Guest

    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
     
    vincent, Jun 22, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Proctor

    ASP Thread Scheduling Anomalies

    Tony Proctor, Mar 2, 2005, in forum: ASP General
    Replies:
    6
    Views:
    282
    Tony Proctor
    Mar 16, 2005
  2. chris guenther
    Replies:
    0
    Views:
    121
    chris guenther
    Apr 10, 2005
  3. Replies:
    1
    Views:
    124
    Ara.T.Howard
    Sep 3, 2005
  4. Mark Volkmann

    thread scheduling

    Mark Volkmann, Jan 10, 2006, in forum: Ruby
    Replies:
    5
    Views:
    132
    Lou Vanek
    Jan 11, 2006
  5. Alex Young
    Replies:
    2
    Views:
    158
    Alex Young
    Nov 29, 2010
Loading...

Share This Page