From: Mikko Rasa Date: Thu, 5 Feb 2015 14:19:01 +0000 (+0200) Subject: Eliminate a possible race condition in thread termination X-Git-Url: http://git.tdb.fi/?p=r2c2.git;a=commitdiff_plain;h=ee92bee98fa084645b17f65cebe4eabf70e4dee9 Eliminate a possible race condition in thread termination In the unlikely event that the thread doesn't terminate fast enough after setting the goal pointer, deleting it would send it a kill signal. Remove this possibility by explicitly jouning the thread. --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 0d0103c..9e74eca 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -29,7 +29,11 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout): TrainRoutePlanner::~TrainRoutePlanner() { - delete thread; + if(thread) + { + thread->join(); + delete thread; + } } TrainRoutePlanner::Result TrainRoutePlanner::plan() @@ -55,9 +59,13 @@ TrainRoutePlanner::Result TrainRoutePlanner::check() { if(result==PENDING && goal) { + if(thread) + { + thread->join(); + delete thread; + thread = 0; + } finalize_plan(); - delete thread; - thread = 0; } return result;