Page 1 of 1

Threads

Posted: 22 Dec 2005, 00:51
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?

Posted: 22 Dec 2005, 01:01
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.

Posted: 22 Dec 2005, 01:05
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...

Posted: 22 Dec 2005, 01:10
by Berion
if you want we can talk about threads tomorrow

i used them in some projects :-(

Posted: 22 Dec 2005, 01:33
by krogothe
ill be out most of the day tomorrow, but im not in a rush...
thanks!

Posted: 22 Dec 2005, 02:34
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.

Posted: 22 Dec 2005, 03:13
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...

Posted: 22 Dec 2005, 09:17
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