From: Axel S. <Axe...@in...> - 2012-08-17 17:21:43
|
Hi Toni, On 17.08.2012, at 16:09, Toni Cebrián wrote: > Yes, but why having and empty MVar freezes everything. I have the value > of interest in st, in fact putStrLn prints that value, but the painting > doesn't happen. > The semantics of an MVar is that it execution blocks when you try to read it when it's empty. Cheers, Axel > And regarding the pattern, I thought that the State monad would be the > way to go instead of doing imperative coding in Haskell. > > Regards. > Toni. > > El 17/08/12 15:47, wag...@se... escribió: >> Quoting Toni Cebrián <an...@gm...>: >> >>> Hi, >>> >>> Instead of using IORef I'm using MVar as the main entry point to >>> state in my Gtk2Hs application. But I'm having strange behaviours >>> and I'm not able to identify the reason. If I write a handler for >>> the onExpose event like: >>> >>> onExpose canvas $ \_ -> (do >>> st <- readMVar ui >>> putStrLn st >>> myPaint st drawin >>> ) >>> everything works fine, but if instead of *readMVar* I use >>> *takeMVar*, the application freezes and the painting code in >>> "myPaint" doesn't show although the putStrLn was printed correctly. >>> Does anybody know what I'm doing wrong here? >> The source of readMVar tells the story: >> >> readMVar m = >> mask_ $ do >> a <- takeMVar m >> putMVar m a >> return a >> >> Ignoring "mask_" for the moment, the point is that readMVar leaves the >> MVar full, and takeMVar doesn't. >> >>> PS. I came to this problem after posting this question >>> <http://stackoverflow.com/questions/12002814/how-to-deal-with-application-state-in-gtk2hs> >>> in SO. Maybe there is a better approach rather than using MVars and IORefs? >> You seem pretty confident that there's a better way than using >> pointers despite everything you read saying otherwise! >> >> ~d >> >> ------------------------------------------------------------------------------ >> Live Security Virtual Conference >> Exclusive live event will cover all the ways today's security and >> threat landscape has changed and how IT managers can respond. Discussions >> will include endpoint security, mobile security and the latest in malware >> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> _______________________________________________ >> Gtk2hs-users mailing list >> Gtk...@li... >> https://lists.sourceforge.net/lists/listinfo/gtk2hs-users > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Gtk2hs-users mailing list > Gtk...@li... > https://lists.sourceforge.net/lists/listinfo/gtk2hs-users |