Browse Source

* 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 -

Jonas Maebe 9 years ago
parent
commit
7eea450a52
1 changed files with 8 additions and 0 deletions
  1. 8 0
      packages/fpmkunit/src/fpmkunit.pp

+ 8 - 0
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