blob: 264df3a45b3a5b3197546cb512c2a2c236a48e12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import Control.Concurrent
import Control.Monad
import Foreign
import Foreign.C.Types
import System.Environment
foreign import ccall safe "finalizerlib.h init_value"
init_value :: Ptr CInt -> IO ()
foreign import ccall safe "finalizerlib.h &finalize_value"
finalize_value :: FinalizerPtr CInt
allocateValue :: IO ()
allocateValue = do
fp <- mallocForeignPtrBytes 10000
withForeignPtr fp init_value
addForeignPtrFinalizer finalize_value fp
main :: IO ()
main = do
[n] <- fmap (fmap read) getArgs
_ <- forkIO (loop n)
loop n
where
loop n = replicateM_ n allocateValue
|