Discussion:
Different speeds required for 2 simultaneous threads
(too old to reply)
Jack
2010-04-22 10:48:43 UTC
Permalink
I just established 2 threads running concurrently in my application, and
they run nicely...
In my design, they should run at different speeds because of their specific
types, say human and vehicle.
I put

pathfind(...)
Sleep(500);

when they finish an iteration.
The threads seem to be running at the same speed which isn't what I
desire...
The pathfind function only differs by a fraction of a second... so that
really doesn't matter.
Is the Sleep API the only way to go to reflect the speed of the targeted
object?
Thanks
Jack
Ulrich Eckhardt
2010-04-22 11:19:11 UTC
Permalink
In my design, they [two threads] should run at different speeds
because of their specific types, say human and vehicle.
I put
pathfind(...)
Sleep(500);
when they finish an iteration.
The threads seem to be running at the same speed which isn't what I
desire...
The pathfind function only differs by a fraction of a second... so that
really doesn't matter.
Is the Sleep API the only way to go to reflect the speed of the targeted
object?
Yes, but I wouldn't do it this way. I would rather your simulated object had
a speed, and then you decide how far it can move based on the last time you
updated the position, i.e. distance=speed*time.

The important difference is that even under lots of load or if pathfinding
takes longer, the objects will keep moving at the same speed, only perhaps
in bigger steps between updates.

Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
Jack
2010-04-22 12:27:46 UTC
Permalink
Post by Ulrich Eckhardt
Yes, but I wouldn't do it this way. I would rather your simulated object had
a speed, and then you decide how far it can move based on the last time you
updated the position, i.e. distance=speed*time.
The important difference is that even under lots of load or if pathfinding
takes longer, the objects will keep moving at the same speed, only perhaps
in bigger steps between updates.
Hi Ulrich
Oh Yes, that reminds me of the old book trick!! Although still haven't made
up my mind, sure it is the way to go!
Thanks
Jack

Loading...