memory leak: forkOS not releasing thread local `Task` struct upon end of thread
I came to notice a memory leak in the runtime system while letting warp use forkOS
and conducting a load test.\\
A minimal snippet to reproduce:
module Main where
import Control.Concurrent
import Control.Monad
main :: IO ()
main = replicateM_ 10000000 $ forkOS $ return ()
This patch will clean up the thread local Task
struct just before threads created by forkOS terminate.
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index c9adf4e..bd4e75d 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -223,6 +223,7 @@ forkOS_createThreadWrapper ( void * entry )
cap = rts_lock();
rts_evalStableIO(&cap, (HsStablePtr) entry, NULL);
rts_unlock(cap);
+ rts_done();
return NULL;
}
I think win32 platforms need an equivalent patch, but unfortunately I cannot verify that. \\ Hence I'm only targeting posix here.