Ticket #4262 (closed bug: fixed)
GHC's runtime never terminates unused worker threads
| Reported by: | Remi | Owned by: | simonmar |
|---|---|---|---|
| Priority: | high | Milestone: | 7.4.1 |
| Component: | Runtime System | Version: | 6.12.3 |
| Keywords: | worker thread foreign function interface | Cc: | ezyang@… |
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | Runtime performance bug | Difficulty: | |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
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.
Change History
Note: See
TracTickets for help on using
tickets.
