I'm looking for information about black hole detection with ghc. I'm getting "<<loop>>" where I don't think there is an actual black hole. I get this message sometimes with the unamb package, which is implemented with unsafePerformIO, concurrency, and killThread, as described in <a href="http://conal.net/blog/posts/functional-concurrency-with-unambiguous-choice/">http://conal.net/blog/posts/functional-concurrency-with-unambiguous-choice/</a> and <a href="http://conal.net/blog/posts/smarter-termination-for-thread-racing/">http://conal.net/blog/posts/smarter-termination-for-thread-racing/</a> .<br>
<br>Suppose I have a definition 'v = unsafePerformIO ...', and v is used more than once. Evaluation (to whnf) of v is begun and the evaluation thread gets killed before evaluation is complete. Then the second use begins. Will the second evaluation be (incorrectly) flagged as a black hole?<br>
<br>I haven't found a simple, reproducible example of incorrect black-hole reporting. My current examples are tied up with the Reactive library. I do have another strange symptom, which is "thread killed" message. I wonder if it's related to the <<loop>> message. Code below.<br>
<br> Thanks, - Conal<br><br><br>import Prelude hiding (catch)<br>import System.IO.Unsafe<br>import Control.Concurrent<br>import Control.Exception<br><br><br>-- *** Exception: thread killed<br>main :: IO ()<br>main = print $ f (f True) where f v = (v `unamb` True) `seq` v<br>
<br>-- | Unambiguous choice operator. Equivalent to the ambiguous choice<br>-- operator, but with arguments restricted to be equal where not bottom,<br>-- so that the choice doesn't matter. See also 'amb'.<br>
unamb :: a -> a -> a<br>unamb a b = unsafePerformIO (evaluate a `race` evaluate b)<br><br>-- | Race two actions against each other in separate threads, and pick<br>-- whichever finishes first. See also 'amb'.<br>
race :: IO a -> IO a -> IO a<br>race a b = do<br> v <- newEmptyMVar<br> let t x = x >>= putMVar v<br> withThread (t a) $ withThread (t b) $ takeMVar v<br> where<br> withThread u v = bracket (forkIO u) killThread (const v)<br>
<br>