Fail: thread killed
I think I have raised the issue some time ago, but don't remember why it hasn't been solved as I would like to. Currently a thread which is killed displays Fail: thread killed, e.g. in the following program: import Concurrent main:: IO () main = do t <- forkIO (threadDelay 100) threadDelay 50 killThread t threadDelay 50 Since the very purpose of killThread is to kill the damn thread, I find it inconvenient to have to wrap any thread which is supposed to be killable with Exception.catch to avoid the message. Worse: it should use block and unblock, otherwise there is a small window where killing the thread will still display the message. I can probably agree that other kinds of exceptions are displayed; maybe the programmer didn't know that exceptions are being thrown and wants the diagnostic. It implies that any well-written code should catch exceptions in all threads it creates (unless he is sure that the code will not throw exceptions), since there shouldn't be compiler's error output from a correct program. Not nice but I can live with that. Should asynchronous exceptions be really displayed in threads other than the main thread? IMHO not. -- __("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Bagley shootout. Was: Lightningspeed haskell
I implemented the programs for hash1 and hash2, but I had to make a lot of changes to FiniteMap to get them to work: - I changed foldl to foldl' (as defined in Hugs). - I made foldFM strict (like foldl'). - I made the datatype FiniteMap strict (put !'s everywhere). I put the programs below, maybe there is a better way to do this. Jan -- Hash1 module Main(main) where import FiniteMap import System writeHex' :: Int -> String writeHex' 0 = "" writeHex' n = c:writeHex' y where x = n `mod` 16 y = n `div` 16 c | x <= 9= toEnum ((fromEnum '0') + x) | otherwise = toEnum ((fromEnum 'A') + x - 10) writeHex :: Int -> String writeHex n | n > 0 = reverse (writeHex' n) | n == 0= "0" | otherwise = '-':(reverse (writeHex' (-n))) main :: IO() main = do { [arg] <- getArgs; let n = read arg fm = listToFM [(writeHex i,i) | i <- [1..n]] c = sum [if elemFM (show i) fm then 1 else 0 | i <- reverse [1..n]] in putStrLn (show c); -- Hash2 module Main(main) where import FiniteMap import System import Maybe foldl' :: (a -> b -> a) -> a -> [b] -> a foldl' _ a [] = a foldl' f a (x:xs) = (foldl' f $! f a x) xs f :: FiniteMap Int Int -> FiniteMap Int Int -> Int -> FiniteMap Int Int f hash1 hash2 k | isJust elt2 = addToFM hash2 k (fromJust elt1 + fromJust elt2) | otherwise = addToFM hash2 k (fromJust elt1) where elt1 = lookupFM hash1 k elt2 = lookupFM hash2 k main :: IO() main = do { [arg] <- getArgs; let n = read arg hash1 = listToFM [(i,i) | i <- [1..1]] keys= concat (take n (repeat (keysFM hash1))) hash2 = foldl' (f hash1) emptyFM keys; h1_1= fromJust (lookupFM hash1 1) h1_ = fromJust (lookupFM hash1 ) h2_1= fromJust (lookupFM hash2 1) h2_ = fromJust (lookupFM hash2 ) in putStrLn (show h1_1 ++ " " ++ show h1_ ++ " " ++ show h2_1 ++ " " ++ show h2_); } ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users