Skip to content

Instantly share code, notes, and snippets.

@msakai
Created April 2, 2023 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msakai/2cacc117731b81f199638ba9144105de to your computer and use it in GitHub Desktop.
Save msakai/2cacc117731b81f199638ba9144105de to your computer and use it in GitHub Desktop.
GHC creates too many windows threads
module Main (main) where
import Control.Concurrent.Async
import Control.Concurrent
import Control.Exception
import Control.Monad
import Data.IORef
import Foreign.C
import System.Random.MWC
main :: IO ()
main = do
g <- createSystemRandom
forever $ do
ref <- newIORef False
let timer = forever $ do
threadDelay (100 * 1000)
writeIORef ref True
withAsync timer $ \_ -> do
replicateM 100 $ do
k <- uniformR (0, 30) g
replicateM_ 10 $
evaluate $ product [1 .. toInteger (k::Int)] `mod` 123456789
shouldPrintStats <- readIORef ref
when shouldPrintStats $ putStrLn "stats"
writeIORef ref False
import Distribution.Simple
main = defaultMain
resolver: lts-13.11
packages:
- .
arch: i386
resolver: nightly-2023-04-02
packages:
- .
arch: x86_64
cabal-version: 1.12
name: thread-leak
version: 0.1.0.0
author: Masahiro Sakai
maintainer: masahiro.sakai@gmail.com
copyright: 2023 Masahiro Sakai
license: BSD3
build-type: Simple
executable thread-leak
main-is: Main.hs
build-depends:
async >=2.2.1 && <2.3
, base >=4.7 && <5
, mwc-random >=0.14 && <0.16
default-language: Haskell2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment