-----------------------------------------------------------------------------
---
+-- |
-- Module : Control.Concurrent
-- Copyright : (c) The University of Glasgow 2001
-- License : BSD-style (see the file libraries/core/LICENSE)
-- Stability : experimental
-- Portability : non-portable
--
--- $Id: Concurrent.hs,v 1.2 2001/08/07 15:25:04 simonmar Exp $
---
-- A common interface to a collection of useful concurrency
-- abstractions.
--
import GHC.TopHandler ( reportStackOverflow, reportError )
import GHC.IOBase ( IO(..) )
import GHC.IOBase ( unsafeInterleaveIO )
-import GHC.Base ( fork# )
-import GHC.Prim ( Addr#, unsafeCoerce# )
+import GHC.Base
#endif
#ifdef __HUGS__
-- cmp_thread in the RTS.
#ifdef __GLASGOW_HASKELL__
-foreign import ccall "cmp_thread" unsafe cmp_thread :: Addr# -> Addr# -> Int
+foreign import ccall unsafe "cmp_thread" cmp_thread :: Addr# -> Addr# -> Int
-- Returns -1, 0, 1
cmpThread :: ThreadId -> ThreadId -> Ordering
instance Ord ThreadId where
compare = cmpThread
+foreign import ccall unsafe "rts_getThreadId" getThreadId :: Addr# -> Int
+
+instance Show ThreadId where
+ showsPrec d (ThreadId t) =
+ showString "ThreadId " .
+ showsPrec d (getThreadId (unsafeCoerce# t))
+
forkIO :: IO () -> IO ThreadId
forkIO action = IO $ \ s ->
case (fork# action_plus s) of (# s1, id #) -> (# s1, ThreadId id #)