<commit_before>{-# OPTIONS -fglasgow-exts #-}

module Main where

import Control.Concurrent
import Control.Exception

choose :: a -> a -> IO a
choose a b = do
   ready <- newMVar ()
   answer <- newEmptyMVar
   a_id <- myForkIO (a `seq` takeMVar ready >> putMVar answer a)
   b_id <- myForkIO (b `seq` takeMVar ready >> putMVar answer b)
   it <- takeMVar answer
   killThread a_id
--   killThread b_id
   return it

-- We need to catch the exception raised by killThread and ignore it.
-- Otherwise the default handler will exit the program when this
-- exception is raised in any thread.

myForkIO :: IO () -> IO ThreadId
myForkIO io = forkIO (Control.Exception.catch io (\e -> return ()))

main = do
   let big = sum [1..]
       small = sum [1..42]
   test1 <- choose big small
   test2 <- choose small big
   print (test1,test2)<commit_msg>[project @ 2002-04-13 05:12:25 by sof] kill thread B too<commit_after>{-# OPTIONS -fglasgow-exts #-}

module Main where

import Control.Concurrent
import Control.Exception

choose :: a -> a -> IO a
choose a b = do
   ready <- newMVar ()
   answer <- newEmptyMVar
   a_id <- myForkIO (a `seq` takeMVar ready >> putMVar answer a)
   b_id <- myForkIO (b `seq` takeMVar ready >> putMVar answer b)
   it <- takeMVar answer
   killThread a_id
   killThread b_id
   return it

-- We need to catch the exception raised by killThread and ignore it.
-- Otherwise the default handler will exit the program when this
-- exception is raised in any thread.

myForkIO :: IO () -> IO ThreadId
myForkIO io = forkIO (Control.Exception.catch io (\e -> return ()))

main = do
   let big = sum [1..]
       small = sum [1..42]
   test1 <- choose big small
   test2 <- choose small big
   print (test1,test2)
{'fraction_non_alphanumeric': 0.10687463893703061, 'fraction_numerical': 0.01733102253032929, 'mean_word_length': 2.900900900900901, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1216487', 'n_tokens_mistral': 600, 'n_tokens_neox': 565, 'n_words': 223}