Prev: Thread Pool Performance in real-time applications
Next: .make file issues/ configuration parameters in headers
From: Jack on 22 Apr 2010 06:48 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
From: Ulrich Eckhardt on 22 Apr 2010 07:19 Jack wrote: > 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
From: Jack on 22 Apr 2010 08:27
> 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 |