Jump to content
  • Advertisement
Sign in to follow this  

Help with Algorithms about threads synchronization

This topic is 1173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the first pseudocode, the cooperative pathfinding thread unstoppingly producing waypoints for

the main thread to consume.

Because the mainthread will delete all waypoints in each iteration, it will get the latest waypoints

from the "CPF" thread, but this has a shortcoming, the mainthread will jerk as the it has to wait

for the cpf thread to compute something and provide him some waypoints.

Are there any good suggestions that I could make some improvements on this.

Should I just slow down the cpf thread, make him produce less waypoints,

and the mainthread will keep on interpolating on his current waypoints?


PS: A path point is a cell that the TimeAStar has reserved for the current window


And also, I am looking into something like conditional variables and futures of the std library.. right? :)



cpf thread -> delete all pathpoints
cpf thread -> create pathpoints
cpf thread -> create waypoints  1,2,3,4,5,6
goto cpf_thread_start:

mainthread -> delete all waypoints
mainthread -> consume next waypoint (wait for cpf thread to provide some)
mainthread -> Intepolating between 2 waypoints
goto main:

waypoints empty
waypoints 1,2,3,4,5,6
waypoints empty
waypoints 2,3,4,5,6
waypoints empty
waypoints 3,4,5,6

The mainthread has to wait for the cpf thread to provide some waypoints
from each iteration
Edited by lucky6969b

Share this post

Link to post
Share on other sites

Use a double buffer?


You have 2 buffers for way points. The main thread has the most current one.

The other buffer is scratch space for the A* thread.


When the A* thread has a new set of points, you swap both buffers (using pointers, so it's really quick).

The main thread then has the new points, and the A* thread has new scratch space it can delete, and recompute.


In this way, the main thread always has the next point to go to.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!