summaryrefslogtreecommitdiff
path: root/ghc/lib/prelude/Concurrent.lhs
blob: 08c5d35cea0846479c6cc59c041d68e85d587ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%
% (c) The AQUA Project, Glasgow University, 1995
%
\section[Concurrent]{Concurrent Haskell constructs}

A common interface to a collection of useful concurrency abstractions.
Currently, the collection only contains the abstractions found in the
{\em Concurrent Haskell} paper (presented at the Haskell Workshop
1995, draft available via \tr{ftp} from
\tr{ftp.dcs.gla.ac.uk/pub/glasgow-fp/drafts}.)  plus a couple of
others. See the paper and the individual files containing the module
definitions for explanation on what they do.

\begin{code}
module Concurrent (
	forkIO,
	par, seq, -- reexported from Parallel

	threadWait, threadDelay,

	ChannelVar..,
	Channel..,
	Semaphore..,
	Merge..,
	SampleVar..,

	-- IVars and MVars come from here, too
	IVar(..), MVar(..), -- for convenience...
	_IVar, _MVar,	-- abstract
	newEmptyMVar, takeMVar, putMVar, newMVar, readMVar, swapMVar,
	newIVar, readIVar, writeIVar

    ) where

import Parallel
import ChannelVar
import Channel
import Semaphore
import Merge
import SampleVar

import PreludeGlaST	( forkST )
import PreludePrimIO	( newEmptyMVar, newMVar, putMVar,
			  readMVar, swapMVar, takeMVar, _MVar,
			  newIVar, readIVar, writeIVar, _IVar,
			  IVar(..), MVar(..),
			  threadWait, threadDelay
			)

forkIO :: IO () -> IO ()

forkIO action s
  = let
	(_, new_s) = action s
    in
    new_s `_fork_` (Right (), s)
 where
    _fork_ x y = case (fork# x) of { 0# -> parError#; _ -> y }
\end{code}