unsafeInterleaveIO ordering

Alastair Reid alastair@reid-consulting-uk.ltd.uk
Fri, 29 Aug 2003 22:01:22 +0100


On Friday 29 August 2003 7:23 pm, Hal Daume wrote:
> if i say:
>
> foo = do
>   putStrLn "a"
>   unsafeInterleaveIO (putStrLn "b" >> putStrLn "c")
>   putStrLn "d"
>
> is it guarenteed that nothing will happen between putting "b" and "c"?
> that is, while the place/time at which the (putStrLn "b" >> putStrLn
> "c") is unspecified, is it the case that the whole thing will be done at
> once?

If you're asking if it is atomic wrt other concurrent haskell threads, the 
answer is no.  

If you're using an eager haskell implementation which does some speculative 
evaluation of things that look cheap and that you might want to evaluate, the 
answer is probably no.  (Because, having decided to do some speculative work 
in the absence of a demand, it might decide it has done enough work after the 
first action, and then later it would finish the job when the result is 
actually demanded.)

But, ff you're using current versions of Hugs or NHC or (using GHC but not 
using threads or turning on speculative evaluation), I'll bet the answer is 
'yes'.

--
Alastair Reid