فهرست منبع

* Fixed synchronize/waitfor issue

git-svn-id: trunk@16145 -
michael 15 سال پیش
والد
کامیت
8dd254b281
1فایلهای تغییر یافته به همراه9 افزوده شده و 1 حذف شده
  1. 9 1
      rtl/unix/tthread.inc

+ 9 - 1
rtl/unix/tthread.inc

@@ -148,9 +148,9 @@ begin
   WRITE_DEBUG('thread done running');
   Result := LThread.FReturnValue;
   WRITE_DEBUG('Result is ',Result);
-  LThread.FFinished := True;
   LFreeOnTerminate := LThread.FreeOnTerminate;
   LThread.DoTerminate;
+  LThread.FFinished := True;
   if LFreeOnTerminate then
     begin
       WRITE_DEBUG('Thread ',ptruint(lthread),' should be freed');
@@ -302,6 +302,14 @@ end;
 function TThread.WaitFor: Integer;
 begin
   WRITE_DEBUG('waiting for thread ',ptruint(FHandle));
+  If (MainThreadID=GetCurrentThreadID) then 
+    {
+     FFinished is set after DoTerminate, which does a synchronize of OnTerminate, 
+     so make sure synchronize works (or indeed any other synchronize that may be 
+     in progress)
+    }
+    While not FFinished do  
+      CheckSynchronize(100);
   WaitFor := WaitForThreadTerminate(FHandle, 0);
   { should actually check for errors in WaitForThreadTerminate, but no }
   { error api is defined for that function                             }