finalizers broken (4.08.2 & 5.00)
Volker Stolz
stolz at I2.Informatik.RWTH-Aachen.DE
Fri May 25 08:47:48 EDT 2001
Okay, I suppose I ain't telling any news here, *but* *usually* people complained
about finalizers being never run. I just discovered that my finalizers are run
*too* *early*, probably because of unsafe{Perform,Interleave}IO:
Consider this fragment which will interleave two lists/streams (they're
created using something similiar getChanContents using unsafeInterleaveIO, too).
> mergeStreams :: [a] -> [b] -> IO [Either a b]
> mergeStreams a b = do
> ch <- newChan
> t1 <- forkIO (writeList2Chan ch (map Left a))
> t2 <- forkIO (writeList2Chan ch (map Right b))
> result <- getChanContents ch
> addFinalizer result (print "fin!" >> killThread t1 >> killThread t2)
> return result
The finalizer is run after I access the second argument of the resulting
stream, although more items are in the list. Removing the addFinalizer statement
will give the desired behaviour.
This happens both in 4.08.2 & 5.00.
--
Abstrakte Syntaxträume.
Volker Stolz * stolz at i2.informatik.rwth-aachen.de * PGP + S/MIME
More information about the Glasgow-haskell-bugs
mailing list