浏览代码

* 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 1 年之前
父节点
当前提交
0314ba9bfd
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      rtl/wasi/tthread.inc

+ 8 - 0
rtl/wasi/tthread.inc

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