[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

passing messages between ruby thread and scheduling

vincent

6/22/2005 3:58:00 AM

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



2 Answers

Syd M.

10/3/2008 8:26:00 AM

0

On Oct 2, 3:58 pm, "John \"C\"" <honestj...@centurytel.net> wrote:
> "Naked Gonad" <bodro...@tiscali.co.uk> wrote in message
>
> news:48e4dbdf$1_2@mk-nntp-2.news.uk.tiscali.com...
>
>
>
> > Tim McGaughy wrote:
> > > Snarky wrote:
> > >> On Thu, 02 Oct 2008 12:21:11 +0100, Naked Gonad wrote these lies,
> > >> denials,
> > >> arrogant assertions, erroneous presuppositions, and/or
> obfuscations:
>
> > >>> What is he frightened of?
>
> > >> His fans. He has a lot in common with Michael Jackson.
>
> > > Well, that certainly explains the priests.
>
> > That's true,there have been quite a few priests caught
> >   abusing kiddies.
>
> > Gonad
>
> It says in the "Good Book" that God cannot look upon "SIN" which covers
> about 90% of the World and 99.9% of America.  He's not afraid of
> anything or anyone but just can't tolerate "Sin-filled" people like Art
> Deco and Pinky Sue Lamb.  He will save and admit to Heaven only those
> who's names are in the "Lamb's Book Of Life" by covering their sins with
> the blood of Jesus by accepting Jesus and repenting of their sins.
>
> The BELIEVER has everything to gain (Heaven) and nothing to lose
> (oblivion)
>
> The NON-Believer has nothing to gain (oblivion) and everything to lose
> (Heaven)
>
> Which one do you want to be when you "croak"?
>
> John C.

Oblivion, asshole.
Heaven's a crock.

PDW

Naked Gonad

10/3/2008 8:40:00 AM

0

Dennis M. Hammes wrote:
> John "C" wrote:
>
>> "Tim McGaughy" <teekem@toast.net> wrote in message
>> news:vKmdnWFyWqkOonjVnZ2dnUVZ_o3inZ2d@posted.toastnet...
>>
>>> John "C" wrote:
>>>
>>>
>>>> The BELIEVER has everything to gain (Heaven) and nothing to lose
>>>> (oblivion)
>>>>
>>>> The NON-Believer has nothing to gain (oblivion) and everything to
>>
>> lose
>>
>>>> (Heaven)
>>>>
>>>> Which one do you want to be when you "croak"?
>>>
>>> Ah, yes, good old Pascal's Wager.
>>>
>>> You have EVERYTHING to lose if you've picked the wrong god.
>>>
>>> I'd love to see the look on your face when Thor won't let you into
>>> Valhalla. Or when Allah doesn't let you into Heaven because you didn't
>>> properly follow the teachings of Mohammad.
>>>
>>> But I'm not that superstitious.
>>
>>
>> I wouldn't risk eternal hell.
>
>
> Why? You certainly don't mind /being/ it.
> (At least temporarily...)
>
>>
>> Go ahead with "non-belief" and always fret where you'll end-up when you
>> croak.
>>
>> HJ
>>
>
>
But it's only religious folk who have this fear factor.
Non believers do not have this fear.
Like I said, religion is based on fear.

Gonad