On Mon, Dec 05, 2005 at 10:50:13AM -0000, Simon Peyton-Jones wrote: > | Yes. Perhaps it would be easier to do it cleanly than arbitrary > | top-level IO bindings? > > It turns out to be easy to provide > > newTVarIO :: a -> IO (TVar a) > > which you can call from inside 'unsafePerformIO'. That means you can > allocate top-level TVars without fuss. > > The whole question of top-level IO remains open, but this will address > the immediate question very nicely.
Unfortunately, in some cases, as in the TimeVar.hs example, the initialization phase is a bit more complex - here I also spawn a new thread. But of course it would be a nice thing for the remaining 95% of cases. Speaking about the whole thing of nested atomically blocks, now that I know how to work around it, I can live with it. > I've also added a SourceForge bug to remind us to fail more tidily if > you do atomically inside atomically. Great! I have an idea going a bit further, but hopefully still quite easy to implement. But I am not sure that it would be a sane thing to do: On each "atomically" check if the current thread is already inside "atomically". If so, then instead of rising an exception we could spawn a new thread to perform the "atomically" block. The result/exception would be propagated to the original thread on a traditional MVar. I think it could be implemented mostly in Haskell. The only missing thing is an IO-primitive: isInAtomicallyBlock :: IO Bool But I fear that doing it this way could introduce a race condition. Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe