From 7eea450a5227b2f1d1e608eae09dd7281ea9ffd7 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Tue, 30 Aug 2016 21:11:05 +0000 Subject: [PATCH] * avoid a datarace in case a worker thread finishes and the main thread sees that it is done before it had the chance to call RTLEventSetEvent() (since then no memory barrier synchronised the thread state with what the main thread would see) git-svn-id: trunk@34401 - --- packages/fpmkunit/src/fpmkunit.pp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/fpmkunit/src/fpmkunit.pp b/packages/fpmkunit/src/fpmkunit.pp index b5fb3df530..9ef075405e 100644 --- a/packages/fpmkunit/src/fpmkunit.pp +++ b/packages/fpmkunit/src/fpmkunit.pp @@ -2832,6 +2832,12 @@ procedure TCompileWorkerThread.execute; begin while not Terminated do begin + { Make sure all of our results are committed before we set (F)Done to true. + While RTLeventSetEvent implies a barrier, once the main thread is notified + it will walk over all threads and look for those that have Done=true -> it + can look at a thread between that thread setting FDone to true and it + calling RTLEventSetEvent } + WriteBarrier; FDone:=true; RTLeventSetEvent(FNotifyMainThreadEvent); RTLeventWaitFor(FNotifyStartTask,500); @@ -7486,6 +7492,8 @@ Var begin if AThread.Done then begin + { synchronise with the WriteBarrier in the thread } + ReadBarrier; if assigned(AThread.APackage) then begin // The thread has completed compiling the package