Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if setNumCapabilities will work [duplicate]

Tags:

haskell

ghc

Given the following program, with GHC 7.6:

import Control.Concurrent
main = do
    setNumCapabilities 8
    putStrLn "After"

If I build with ghc --make and run I get:

main: setNumCapabilities: not supported in the non-threaded RTS
After

The warning about the non-threaded RTS comes because I didn't build with -threaded. I would like to modify this code so that it doesn't print anything even if it didn't work. For example, if I could detect that the RTS was non-threaded, then I could avoid the setNumCapabilities. I don't want to put something on the stdout of the calling program.

like image 791
Neil Mitchell Avatar asked Mar 19 '23 19:03

Neil Mitchell


1 Answers

Check rtsSupportsBoundThreads before.

Also see: How to detect if a program has been compiled using -threaded?

like image 153
chi Avatar answered Apr 01 '23 06:04

chi