From 492e38069c9ca4eb6132fac300532840e4880a02 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Fri, 23 Aug 2024 12:07:21 +0300 Subject: [PATCH] + WebAssembly threads: introduced TWasmThread.ThreadHasFinished boolean --- rtl/wasi/systhrd.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rtl/wasi/systhrd.inc b/rtl/wasi/systhrd.inc index 1ae66a75f5..ae7800b1c6 100644 --- a/rtl/wasi/systhrd.inc +++ b/rtl/wasi/systhrd.inc @@ -50,6 +50,7 @@ Type TWasmThread = Record InitialStackPointer : Pointer; InitTLSBase : Pointer; + ThreadHasFinished : Boolean; ID : LongInt; // Allocated by host ThreadFunction : TThreadFunc; ThreadFunctionArg : Pointer; @@ -446,6 +447,16 @@ asm local.get 0 ;; tid local.get 1 ;; start_arg call $FPCWasmThreadStartPascal + + ;; Set start_arg^.ThreadHasFinished to true. + ;; This is done from within inline asm, after the pascal code has finished + ;; executing, because it indicates that the thread no longer needs its TLS + ;; block and linear stack block, so this means it's safe to free them. + local.get 1 ;; start_arg + i32.const 8 ;; offset to ThreadHasFinished + i32.add + i32.const 1 ;; true + i32.atomic.store8 end; exports wasi_thread_start;