I have an interesting problem, it seems simple but I can seem to find any solutions to it online or on stackoverflow.
I have a program which generates threads to search down paths of a maze in order to find a way out. Upon reaching a dead end a thread returns to the junction it came from and marks the direction as dead so no other thread looks down that way. Similarly, upon reaching the way out the thread returns and marks the direction it came from as golden, if a thread finds a golden path it ignores everything else and follows the golden directions to the exit and terminates.
My problem is if a thread finds the exit I want it to return all the way to the beginning junction marking the golden directions on the way before being booted off the processor for using up it's share of processor time. Currently a thread which has found the exit can get halfway through marking the way out when it's quantum of time on the processor runs out and it gets kicked out of the processor for the time being, so some threads still exploring the earlier parts of the maze wander about wasting time when they could be on their way out.
How do I ensure that a thread 't' which has just found the exit, stays on the processor until it terminates itself.
Thanks in advance.