Skip to content

Instantly share code, notes, and snippets.

@ephemient
Created December 30, 2019 08:50
Show Gist options
  • Save ephemient/6acbfdc1e5fec57cd80410b0fdc59f50 to your computer and use it in GitHub Desktop.
Save ephemient/6acbfdc1e5fec57cd80410b0fdc59f50 to your computer and use it in GitHub Desktop.
A forkIO'ed thread that is reading from the TTY cannot be killed?
#!/usr/bin/env stack
-- stack script --resolver lts --package unix
module Main where
import Control.Concurrent
import Control.Concurrent.MVar
import System.Posix
main :: IO ()
main = do
sync <- newEmptyMVar
threadId <- forkIO $ putMVar sync () >> fdRead stdInput 1 >>= print
takeMVar sync
putStrLn "kill?"
killThread threadId
putStrLn "kill!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment