Skip to main content
gamedev.net
🔒 Locked

Multitasking....

Started by Linc Jul 10, 2003 at 2:52 PM 10 replies 900+ views
Original Post
Linc
Linc
Hey, I''m working on an A-Life simulator right now for an indepentant studies thing at school. I was wondering if anyone has any ideas on how to get all the little critters to be doing there thing at once? I''ve thought of using threads for each critter, but I''m going to have at the very least a 100 critters, and I have a feeling this would really trip up the system. I read somewhere that the UT engine had some way it simulated threads but it was a lot faster then how windows does it. Does anyone have any info on that or any other ways I could do this? thanks, Joel
Eskhan
Eskhan
100 threads should probably not be a problem. Each thread doesn't produce much overhead. Of course, the more threads you have and the more code each executes the slower the program will run. If you're concerned that your threads won't execute when you have that many of them, don't worry. At least on windows the scheduler makes sure that a thread won't block execution of other code by giving it a time limit (usually between 15 and 30 ms) before it stops executing the thread and moves over to another one.

--------------------
Though this program be madness, yet there is a method in't

[edited by - Eskhan on July 10, 2003 4:08:09 PM]
--------------------Though this program be madness, yet there is a method in't
Wildfire
Wildfire
quote:

I was wondering if anyone has any ideas on how to get all the little critters to be doing there thing at once?


Yes, get a multiprocessor system. On a single processor system things will never happen at once (if you leave that fancy P4 stuff aside for now).

If you decide to use threads you basically leave it up to the system to decide when it does what. With a lot of threads the system will be doing a lot of management and little work. Thus it can be rather ineffective. Plus you get to play with things like thread synchronising etc. etc.

One way could be to put all your critters in an array/vector/list/whatever and iterate over all of them each cycle.
How do I set my laser printer n stun? o
Eskhan
Eskhan
Depends on what you mean by at once, you probably won''t notice the difference anyway if the threads execute in round-robin fashion instead of all executing simultaneously.
--------------------Though this program be madness, yet there is a method in't
Linc
Linc
I had been thinking about using just a simple round-robin approach, but I wasn''t sure if it would start of affect the way the creatures interact with each other and things would really suck if I got everything up and running only to see a creature eating while another is trying to breed with it. Plus the way its being designed right now, I worried about maybe getting some kind resource dead lock.

As for only a multi-processro system, I don''t think that would really be possible around here. The only systems like that here are the system critical network servers, and I doubt they would let a student play on those.

For the threads, around 100 would be the minumum, I was expecting somewhere between 500 to 1500 for an adequate gene pool.
Yanroy
Yanroy
I would make the world/critters in an array and iterate through it. To get the _appearance_ of simultaneous execution, you could have 2 such arrays. One is "present" and one is "future". All the critters, laws of physics, etc. would make decisions and interact with the "present" but any changes they make in the world and themselves would be saved to "future". Then at the end of an iteration, overwrite "present" with "future" and start iterating again. This is very similar to the way DirectDraw works with surface flipping...

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
Eskhan
Eskhan
The future array is not a bad idea. That way you could see what actions they are going to take in the next iteration so if the 'future array' tells you that one creature is trying to breed with a creature that is trying to eat it you change their actions before they happen, and then decide their actions from a new array with the corrected actions so things happen correctly.

edit:
quote:

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming



not really related, but that made me chuckle, many times i catch myself almost ending a sentence with a semicolon

--------------------
Though this program be madness, yet there is a method in't

[edited by - Eskhan on July 10, 2003 6:15:16 PM]
--------------------Though this program be madness, yet there is a method in't
Linc
Linc
Yeah, I like the future array thing. Thanks for the idea Yanroy.
JohnBolton
JohnBolton
My opinion -- don''t use threads. That will just create a synchronization nightmare.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
S1CA
S1CA
100 threads is excessive, particularly for use in AI.

I''d suggest looking at Microthreads/The Microthread Pattern.

You could alternatively look at Fibers (CreateFiber etc) in Windows.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.