浏览代码

* 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 年之前
父节点
当前提交
7eea450a52
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      packages/fpmkunit/src/fpmkunit.pp

+ 8 - 0
packages/fpmkunit/src/fpmkunit.pp

@@ -2832,6 +2832,12 @@ procedure TCompileWorkerThread.execute;
 begin
 begin
   while not Terminated do
   while not Terminated do
     begin
     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;
     FDone:=true;
     RTLeventSetEvent(FNotifyMainThreadEvent);
     RTLeventSetEvent(FNotifyMainThreadEvent);
     RTLeventWaitFor(FNotifyStartTask,500);
     RTLeventWaitFor(FNotifyStartTask,500);
@@ -7486,6 +7492,8 @@ Var
   begin
   begin
     if AThread.Done then
     if AThread.Done then
       begin
       begin
+        { synchronise with the WriteBarrier in the thread }
+        ReadBarrier;
         if assigned(AThread.APackage) then
         if assigned(AThread.APackage) then
           begin
           begin
             // The thread has completed compiling the package
             // The thread has completed compiling the package