Threads

Threads

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Threads

Post by krogothe »

I was looking at the code to get them working and it looks pretty daunting, so i need to make sure they are the right way forward!
Can i specify (and vary, runtime) the amount of processor time (in %, since it will run on different machines, absolute numbers wont work)?
Does it slow the program down compared to a single thread doing the same thing?
What happens when two places in memory are being accessed/changed at the same time or is that not an issue?
Berion
Posts: 33
Joined: 01 Oct 2005, 15:15

Post by Berion »

I would not use threads.
Can i specify (and vary, runtime) the amount of processor time (in %, since it will run on different machines, absolute numbers wont work)?
no, only priority or you are a genius and programme your own :-D
Does it slow the program down compared to a single thread doing the same thing?
You should do completely different things in your threads or they are slower and more dangerous
What happens when two places in memory are being accessed/changed at the same time or is that not an issue?
crash or undefined behaviour :-D
there are some ways(mutex,...) but then one thread must wait for the other .

there are many more great "features" of threads which make your life to hell. And finding bugs will be way more fun!

So if you don't need them don't use them.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Well, i kinda need them :(
either that or a 40Ghz PC (if i get that pc then the AI will be a lot smarter than with threads though)
I just need a way to assign limited processor time to certain functions...
Berion
Posts: 33
Joined: 01 Oct 2005, 15:15

Post by Berion »

if you want we can talk about threads tomorrow

i used them in some projects :-(
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

ill be out most of the day tomorrow, but im not in a rush...
thanks!
SoftNum
Posts: 22
Joined: 28 Nov 2005, 22:07

Post by SoftNum »

Threads arn't that bad, you just need to be careful.

Threads arn't going to get you any more speed, it just allows you to parallel a lot of tasks. Basically in my AI I'm using them to make sure my Update() calls dont' back up the server.

However, there are a lot of 'gotchas' in threading and such. But if you divide your AI into distict tasks, and are careful about shared objects (or use controls to ensure serial(one at a time) access to them) you should be fine.

Another note is that unless you're using MFC, it's sorta hard to use threads in C++ classes, there's a few gotchas.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

whats MFC and gotchas?
Im just gonna use the threads to dynamically scale and distribute processing time... Cant go with the simple beehive attack system any longer so ill need threads to move on in that area...
cain
AI Developer
Posts: 124
Joined: 09 Aug 2005, 10:04

Post by cain »

krogothe wrote:Well, i kinda need them :(
either that or a 40Ghz PC (if i get that pc then the AI will be a lot smarter than with threads though)
I just need a way to assign limited processor time to certain functions...
what you really need is a better algorithm, then
don't expect to achieve that speed.

I've dwelled with some similar issues already, if you tell me what you need that 40Gig for, meby I can help to find a way out.
feel free to send me a private message
Post Reply

Return to “AI”