expose the value of +RTS -N as GHC.Conc.numCapabilities (see #1733)
authorSimon Marlow <simonmar@microsoft.com>
Tue, 9 Oct 2007 13:20:42 +0000 (13:20 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Tue, 9 Oct 2007 13:20:42 +0000 (13:20 +0000)
GHC/Conc.lhs

index 55da1ac..094ff05 100644 (file)
@@ -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