id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
4262,GHC's runtime never terminates unused worker threads,Remi,simonmar,"When concurrently calling safe FFI functions, worker OS threads are created. These threads then never quit.

The following toy program creates 30k OS threads (which is fine because that's exactly what it asks for) which are then never ""garbage collected"": 30k threads and over 230g of VM are hanging around until the program exits.

{{{
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where

import Control.Concurrent
import Control.Monad
import Foreign.C.Types
import System.Mem

foreign import ccall safe sleep :: CUInt -> IO ()

main = do
    replicateM_ 30000 $ forkIO $ sleep 2
    getLine
    -- do other stuff
}}}

P.S. Of course I should simply use threadDelay in this case. The real program performs up to a few hundred concurrent fdatasync calls.",bug,closed,high,7.4.1,Runtime System,6.12.3,fixed,worker thread foreign function interface,ezyang@…,Unknown/Multiple,Unknown/Multiple,Runtime performance bug,,,,,
