From 956c7b881b7a356626776f032e0076e7b35fb641 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Tue, 9 Oct 2007 13:20:42 +0000 Subject: [PATCH] expose the value of +RTS -N as GHC.Conc.numCapabilities (see #1733) --- GHC/Conc.lhs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/GHC/Conc.lhs b/GHC/Conc.lhs index 55da1ac..094ff05 100644 --- a/GHC/Conc.lhs +++ b/GHC/Conc.lhs @@ -28,6 +28,7 @@ module GHC.Conc -- * Forking and suchlike , forkIO -- :: IO a -> IO ThreadId , forkOnIO -- :: Int -> IO a -> IO ThreadId + , numCapabilities -- :: Int , childHandler -- :: Exception -> IO () , myThreadId -- :: IO ThreadId , killThread -- :: ThreadId -> IO () @@ -190,6 +191,17 @@ forkOnIO (I# cpu) action = IO $ \ s -> where action_plus = catchException action childHandler +-- | the value passed to the @+RTS -N@ flag. This is the number of +-- Haskell threads that can run truly simultaneously at any given +-- time, and is typically set to the number of physical CPU cores on +-- the machine. +numCapabilities :: Int +numCapabilities = unsafePerformIO $ do + n <- peek n_capabilities + return (fromIntegral n) + +foreign import ccall "&n_capabilities" n_capabilities :: Ptr CInt + childHandler :: Exception -> IO () childHandler err = catchException (real_handler err) childHandler -- 1.7.10.4