Created
September 5, 2017 14:17
-
-
Save raichoo/97ed5118f3fd0bc5543cd5010584e998 to your computer and use it in GitHub Desktop.
Playing with capabilities.
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 where | |
import Control.Monad | |
import Control.Concurrent | |
import Text.Printf | |
import Foreign.C.Types | |
foreign import ccall safe "getchar" c_getchar :: IO CChar | |
loop :: Int -> IO () | |
loop x = do | |
forever $ do | |
tid <- myThreadId | |
cap <- fst <$> threadCapability tid | |
c_getchar | |
cap' <- fst <$> threadCapability tid | |
when (cap /= cap') $ | |
printf "Thread changed capability: %d\t(%d, %d)\n" x cap cap' | |
{- | |
$ ghc -threaded Test.hs -o Test -with-rtsopts=-N2 | |
$ yes | ./Test | |
-} | |
main :: IO () | |
main = do | |
forM_ [1..32] $ | |
forkIO . loop | |
threadDelay (10 * 1000 * 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment