Created
April 2, 2023 03:47
-
-
Save msakai/2cacc117731b81f199638ba9144105de to your computer and use it in GitHub Desktop.
GHC creates too many windows threads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Distribution.Simple | |
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolver: lts-13.11 | |
packages: | |
- . | |
arch: i386 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolver: nightly-2023-04-02 | |
packages: | |
- . | |
arch: x86_64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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