[Haskell-cafe] Extending GHCi

Anthony Cowley acowley at seas.upenn.edu
Mon Feb 7 17:10:32 CET 2011


On Sun, Feb 6, 2011 at 11:59 PM, C K Kashyap <ckkashyap at gmail.com> wrote:
>>
>> $ ghci
>> GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
>> Loading package ghc-prim ... linking ... done.
>> Loading package integer-gmp ... linking ... done.
>> Loading package base ... linking ... done.
>> Loading package ffi-1.0 ... linking ... done.
>> Prelude> :m +Data.IORef Control.Concurrent Control.Monad
>> Prelude Data.IORef Control.Concurrent Control.Monad> msg <- newIORef
>> "Hello"
>> Prelude Data.IORef Control.Concurrent Control.Monad> let echo =
>> forever $ readIORef msg >>= putStrLn >> threadDelay 3000000
>> Prelude Data.IORef Control.Concurrent Control.Monad> t <- forkIO echo
>> Hello
>> Prelude Data.IORef Control.Concurrent Control.Monad> Hello
>> Hello
>> writeIORefHello msg "World"
>> Prelude Data.IORef Control.Concurrent Control.Monad> World
>> World
>
> Thanks ... this is the possibility I was looking for. Btw, I am thinking I'd
> need to use STM to synchronize right?
> Regards,
> Kashyap

You need STM when you need groups of references to change
simultaneously as perceived by concurrent processes.

Anthony



More information about the Haskell-Cafe mailing list