> In ghc there are IORefs and IOArrays (in the IOExts module) - like
> ML's refs, but they live in the IO monad. There are also STRefs and
> STArrays (in the ST and LazyST modules), which are similar, but can
> be safely encapsulated in a pure function.
> 
> For threads there are MVars (in the Concurrent module), which can
> be either empty or full and can be used for synchronization and
> passing data between threads. There are also some other kinds of
> "variables" built on top of MVars in the Concurrent module (CVars,
> Chans, semaphores, SampleVars).

Putting these together, it sounds like what you're after is an IOArray
protected by an MVar.  eg.

        type MyArray a = MVar (IOArray a)

A thread wanting to read or update the array must take it from the MVar
first, and put it back afterwards.

Cheers,
        Simon

Reply via email to