Browse Source

+ TThread.WaitFor needs to call CheckSynchronize

git-svn-id: trunk@1661 -
florian 20 years ago
parent
commit
375bc7bbb0
2 changed files with 19 additions and 2 deletions
  1. 3 0
      rtl/linux/tthread.inc
  2. 16 2
      rtl/win32/tthread.inc

+ 3 - 0
rtl/linux/tthread.inc

@@ -294,6 +294,9 @@ end;
 function TThread.WaitFor: Integer;
 function TThread.WaitFor: Integer;
 begin
 begin
   WRITE_DEBUG('waiting for thread ',FHandle);
   WRITE_DEBUG('waiting for thread ',FHandle);
+  if GetCurrentThreadID=MainThreadID then
+    while not(FFinished) do
+      CheckSynchronize(1000);
   WaitFor := WaitForThreadTerminate(FHandle, 0);
   WaitFor := WaitForThreadTerminate(FHandle, 0);
   WRITE_DEBUG('thread terminated');
   WRITE_DEBUG('thread terminated');
 end;
 end;

+ 16 - 2
rtl/win32/tthread.inc

@@ -205,10 +205,24 @@ end;
 function TThread.WaitFor: Integer;
 function TThread.WaitFor: Integer;
 var
 var
   Msg: TMsg;
   Msg: TMsg;
+  WaitHandles : array[0..1] of THandle;
 begin
 begin
   if GetCurrentThreadID = MainThreadID then
   if GetCurrentThreadID = MainThreadID then
-    while MsgWaitForMultipleObjects(1, FHandle, False, INFINITE, QS_SENDMESSAGE) = WAIT_OBJECT_0 + 1 do
-      PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE)
+    begin
+      WaitHandles[0]:=FHandle;
+      WaitHandles[1]:=THandle(SynchronizeTimeoutEvent);
+      while true do
+        begin
+          case MsgWaitForMultipleObjects(2, WaitHandles, False, INFINITE, QS_SENDMESSAGE) of
+            WAIT_OBJECT_0:
+              break;
+            WAIT_OBJECT_0+1:
+              CheckSynchronize;
+            WAIT_OBJECT_0+2:
+              PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE)
+          end;
+        end;
+    end
   else
   else
     WaitForSingleObject(ulong(FHandle), INFINITE);
     WaitForSingleObject(ulong(FHandle), INFINITE);
   GetExitCodeThread(FHandle, DWord(Result));
   GetExitCodeThread(FHandle, DWord(Result));