[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / lib / prelude / Concurrent.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1995
3 %
4 \section[Concurrent]{Concurrent Haskell constructs}
5
6 A common interface to a collection of useful concurrency abstractions.
7 Currently, the collection only contains the abstractions found in the
8 {\em Concurrent Haskell} paper (presented at the Haskell Workshop
9 1995, draft available via \tr{ftp} from
10 \tr{ftp.dcs.gla.ac.uk/pub/glasgow-fp/drafts}.)  plus a couple of
11 others. See the paper and the individual files containing the module
12 definitions for explanation on what they do.
13
14 \begin{code}
15 module Concurrent (
16         forkIO,
17         par, seq, -- reexported from Parallel
18
19         threadWait, threadDelay,
20
21         ChannelVar..,
22         Channel..,
23         Semaphore..,
24         Merge..,
25         SampleVar..,
26
27         -- IVars and MVars come from here, too
28         IVar(..), MVar(..), -- for convenience...
29         _IVar, _MVar,   -- abstract
30         newEmptyMVar, takeMVar, putMVar, newMVar, readMVar, swapMVar,
31         newIVar, readIVar, writeIVar
32
33     ) where
34
35 import Parallel
36 import ChannelVar
37 import Channel
38 import Semaphore
39 import Merge
40 import SampleVar
41
42 import PreludeGlaST     ( forkST )
43 import PreludePrimIO    ( newEmptyMVar, newMVar, putMVar,
44                           readMVar, swapMVar, takeMVar, _MVar,
45                           newIVar, readIVar, writeIVar, _IVar,
46                           IVar(..), MVar(..),
47                           threadWait, threadDelay
48                         )
49
50 forkIO :: IO () -> IO ()
51
52 forkIO action s
53   = let
54         (_, new_s) = action s
55     in
56     new_s `_fork_` (Right (), s)
57  where
58     _fork_ x y = case (fork# x) of { 0# -> parError#; _ -> y }
59 \end{code}