Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Need help designing tool

Name: Anonymous 2006-11-05 9:50

Okay, lets say I have a list of objects.  Each object can perform an action every five seconds, the time it takes to perform an action is random and might very well be more than five seconds.

How do I keep all the objects performing their actions as soon as possible in order to get the best throughput?  Threads, I suppose, but what should I store the objects in, and how do I check when one is done.

Perhaps if I put a mutex (I hope that's the right name) in each object, along with a timestamp.  A priority queue?  If so, do I sort on the timestamps?  I guess I do, thanks for the help!

Name: Anonymous 2006-11-05 10:59

Alright, this is my algorithm.  Can I improve it?  I do the mutex locking, unlocking inside the spam function, should I instead use the synchronize function in the Mutex class?
while true
    pq.each do |p|
        if Time.now > (pq.first.priority + 5) && !pq.first.mutex.locked?
            pq.first.priority = Time.now
            Thread.start do
                spam pq.first
            end
            break
        end
    end
    pq.sort!
end

Name: Anonymous 2006-11-05 11:09

Oops, I forgot to change pq.first to p >_<.

Not too slow still though.
http://dis.4chan.org/read/lang/1162543556/12,550

Name: Anonymous 2006-11-05 11:18

I suppose this is both faster and better.
http://dis.4chan.org/read/lang/1162543556/551,1000
while true
    pq.each do |p|
        if Time.now > (p.priority + 5) && !p.mutex.locked?
            p.priority += 20
            Thread.start do
                p.mutex.synchronize do
                    spam p
                end
            end
            break
        end
    end
    pq.sort!
end

Name: Anonymous 2006-11-05 11:22

And if I did not already say so, I change p.priority in spam.  I guess I should rather do it in the Thread block, as it doesn't really belong in the spam function.:wq

Name: Anonymous 2006-11-05 16:15

Asynchronous delegates.

Name: Anonymous 2006-11-05 16:24

WHAT

Name: Anonymous 2006-11-05 16:28

USE POE

Name: Anonymous 2006-11-05 17:42

>>8
Perl Object Environment?  YOU SON OF A BITCH!!

Name: Anonymous 2011-01-31 21:35

<-- check em dubz

Name: tray 2012-03-15 16:26

hey ya all, guten tag!

Name: Sgt.Kabu엖榾kimanꤐ㕶 2012-05-28 20:47

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List