[Haskell-cafe] Weird thing happened when I use gtk2hs with concurrent.

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Wed Jun 24 03:38:16 EDT 2009


This is the weird code, please see line 61.

20 cpuNew :: IO CPU
21 cpuNew = do
22   self <- meterNew
23   usage <- newIORef $ CPUusage 0 0 0 0 0 0 0 0
24   self `on` realize $ do
25     forkIO $ redraw self usage
33     return ()
34   return self
35   where
56     redraw self usage = do
57       newUsage <- getUsage
58       oldUsage <- readIORef usage
59       postGUISync $ meterDraw self "Cpu" $ computeIdle $ diff
newUsage oldUsage
60       writeIORef usage newUsage
61       threadDelay 10000 -- ten seconds, but it just refresh crazy!
62       redraw self usage


More information about the Haskell-Cafe mailing list