Sign in to follow this  
lucky6969b

Help with Algorithms about threads synchronization

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? :)

Thanks

Jack

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this