Browse Source

* WebAssembly threads: in TThread.WaitFor, call CheckSynchronize in a loop,
while waiting on a thread that isn't finished, but the waiting happens on the
main thread. This fixes the hang in test tb0636.pp

Nikolay Nikolov 11 months ago
parent
commit
0314ba9bfd
1 changed files with 8 additions and 0 deletions
  1. 8 0
      rtl/wasi/tthread.inc

+ 8 - 0
rtl/wasi/tthread.inc

@@ -216,6 +216,14 @@ end;
 function TThread.WaitFor: Integer;
 function TThread.WaitFor: Integer;
 
 
 begin
 begin
+  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(FThreadID,-1);
   WaitFor:=WaitForThreadTerminate(FThreadID,-1);
   { should actually check for errors in WaitForThreadTerminate, but no }
   { should actually check for errors in WaitForThreadTerminate, but no }
   { error api is defined for that function                             }
   { error api is defined for that function                             }