home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 876 / hugs.sis / ChannelVar.lhs < prev    next >
LaTeX Document  |  2000-09-21  |  1.3 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime text/x-matlab default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 25 0a 25 20 28 63 29 20 | 54 68 65 20 47 52 41 53 |%.% (c) |The GRAS|
|00000010| 50 2f 41 51 55 41 20 50 | 72 6f 6a 65 63 74 2c 20 |P/AQUA P|roject, |
|00000020| 47 6c 61 73 67 6f 77 20 | 55 6e 69 76 65 72 73 69 |Glasgow |Universi|
|00000030| 74 79 2c 20 31 39 39 35 | 0a 25 0a 5c 73 65 63 74 |ty, 1995|.%.\sect|
|00000040| 69 6f 6e 5b 43 68 61 6e | 6e 65 6c 56 61 72 5d 7b |ion[Chan|nelVar]{|
|00000050| 43 68 61 6e 6e 65 6c 20 | 76 61 72 69 61 62 6c 65 |Channel |variable|
|00000060| 73 7d 0a 0a 43 68 61 6e | 6e 65 6c 20 76 61 72 69 |s}..Chan|nel vari|
|00000070| 61 62 6c 65 73 2c 20 61 | 72 65 20 6f 6e 65 2d 65 |ables, a|re one-e|
|00000080| 6c 65 6d 65 6e 74 20 63 | 68 61 6e 6e 65 6c 73 20 |lement c|hannels |
|00000090| 64 65 73 63 72 69 62 65 | 64 20 69 6e 20 74 68 65 |describe|d in the|
|000000a0| 20 43 6f 6e 63 75 72 72 | 65 6e 74 0a 48 61 73 6b | Concurr|ent.Hask|
|000000b0| 65 6c 6c 20 70 61 70 65 | 72 20 28 61 76 61 69 6c |ell pape|r (avail|
|000000c0| 61 62 6c 65 20 66 72 6f | 6d 20 40 66 74 70 3a 2f |able fro|m @ftp:/|
|000000d0| 2f 66 74 70 2e 64 63 73 | 2e 67 6c 61 2e 61 63 2e |/ftp.dcs|.gla.ac.|
|000000e0| 75 6b 2f 70 75 62 2f 67 | 6c 61 73 67 6f 77 2d 66 |uk/pub/g|lasgow-f|
|000000f0| 70 2f 64 72 61 66 74 73 | 40 29 0a 0a 5c 62 65 67 |p/drafts|@)..\beg|
|00000100| 69 6e 7b 63 6f 64 65 7d | 0a 6d 6f 64 75 6c 65 20 |in{code}|.module |
|00000110| 43 68 61 6e 6e 65 6c 56 | 61 72 0a 20 20 20 20 20 |ChannelV|ar. |
|00000120| 20 20 28 0a 09 20 7b 2d | 20 61 62 73 74 72 61 63 | (.. {-| abstrac|
|00000130| 74 20 2d 7d 0a 20 20 20 | 20 20 20 20 20 20 43 56 |t -}. | CV|
|00000140| 61 72 2c 0a 09 20 6e 65 | 77 43 56 61 72 2c 09 2d |ar,.. ne|wCVar,.-|
|00000150| 2d 3a 3a 20 49 4f 20 28 | 43 56 61 72 20 61 29 0a |-:: IO (|CVar a).|
|00000160| 09 20 77 72 69 74 65 43 | 56 61 72 2c 09 2d 2d 3a |. writeC|Var,.--:|
|00000170| 3a 20 43 56 61 72 20 61 | 20 2d 3e 20 61 20 2d 3e |: CVar a| -> a ->|
|00000180| 20 49 4f 20 28 29 0a 09 | 20 72 65 61 64 43 56 61 | IO ()..| readCVa|
|00000190| 72 2c 09 2d 2d 3a 3a 20 | 43 56 61 72 20 61 20 2d |r,.--:: |CVar a -|
|000001a0| 3e 20 49 4f 20 61 0a 09 | 20 4d 56 61 72 0a 0a 20 |> IO a..| MVar.. |
|000001b0| 20 20 20 20 20 20 29 20 | 77 68 65 72 65 0a 0a 69 | ) |where..i|
|000001c0| 6d 70 6f 72 74 20 50 72 | 65 6c 75 64 65 0a 69 6d |mport Pr|elude.im|
|000001d0| 70 6f 72 74 20 43 6f 6e | 63 42 61 73 65 0a 5c 65 |port Con|cBase.\e|
|000001e0| 6e 64 7b 63 6f 64 65 7d | 0a 0a 40 4d 56 61 72 73 |nd{code}|..@MVars|
|000001f0| 40 20 70 72 6f 76 69 64 | 65 20 74 68 65 20 62 61 |@ provid|e the ba|
|00000200| 73 69 63 20 6d 65 63 68 | 61 6e 69 73 6d 73 20 66 |sic mech|anisms f|
|00000210| 6f 72 20 73 79 6e 63 68 | 72 6f 6e 69 73 69 6e 67 |or synch|ronising|
|00000220| 20 61 63 63 65 73 73 20 | 74 6f 20 61 20 73 68 61 | access |to a sha|
|00000230| 72 65 64 0a 72 65 73 6f | 75 72 63 65 2e 20 40 43 |red.reso|urce. @C|
|00000240| 56 61 72 73 40 2c 20 6f | 72 20 63 68 61 6e 6e 65 |Vars@, o|r channe|
|00000250| 6c 20 76 61 72 69 61 62 | 6c 65 73 2c 20 70 72 6f |l variab|les, pro|
|00000260| 76 69 64 65 20 61 6e 20 | 61 62 73 74 72 61 63 74 |vide an |abstract|
|00000270| 69 6f 6e 20 74 68 61 74 | 20 67 75 61 72 61 6e 74 |ion that| guarant|
|00000280| 65 65 0a 74 68 61 74 20 | 74 68 65 20 70 72 6f 64 |ee.that |the prod|
|00000290| 75 63 65 72 20 69 73 20 | 6e 6f 74 20 61 6c 6c 6f |ucer is |not allo|
|000002a0| 77 65 64 20 74 6f 20 72 | 75 6e 20 72 69 6f 74 2c |wed to r|un riot,|
|000002b0| 20 62 75 74 20 65 6e 66 | 6f 72 63 65 73 20 74 68 | but enf|orces th|
|000002c0| 65 20 69 6e 74 65 72 6c | 65 61 76 65 64 0a 61 63 |e interl|eaved.ac|
|000002d0| 63 65 73 73 20 74 6f 20 | 74 68 65 20 63 68 61 6e |cess to |the chan|
|000002e0| 6e 65 6c 20 76 61 72 69 | 61 62 6c 65 2c 69 2e 65 |nel vari|able,i.e|
|000002f0| 2e 2c 20 61 20 70 72 6f | 64 75 63 65 72 20 69 73 |., a pro|ducer is|
|00000300| 20 66 6f 72 63 65 64 20 | 74 6f 20 77 61 69 74 20 | forced |to wait |
|00000310| 75 70 20 66 6f 72 0a 61 | 20 63 6f 6e 73 75 6d 65 |up for.a| consume|
|00000320| 72 20 74 6f 20 72 65 6d | 6f 76 65 20 74 68 65 20 |r to rem|ove the |
|00000330| 70 72 65 76 69 6f 75 73 | 20 76 61 6c 75 65 20 62 |previous| value b|
|00000340| 65 66 6f 72 65 20 69 74 | 20 63 61 6e 20 64 65 70 |efore it| can dep|
|00000350| 6f 73 69 74 20 61 20 6e | 65 77 20 6f 6e 65 20 69 |osit a n|ew one i|
|00000360| 6e 20 74 68 65 20 40 43 | 56 61 72 40 2e 0a 0a 5c |n the @C|Var@...\|
|00000370| 62 65 67 69 6e 7b 63 6f | 64 65 7d 0a 0a 64 61 74 |begin{co|de}..dat|
|00000380| 61 20 43 56 61 72 20 61 | 0a 20 3d 20 43 56 61 72 |a CVar a|. = CVar|
|00000390| 20 28 4d 56 61 72 20 61 | 29 20 20 20 20 20 2d 2d | (MVar a|) --|
|000003a0| 20 70 72 6f 64 20 2d 3e | 20 63 6f 6e 73 0a 20 20 | prod ->| cons. |
|000003b0| 20 20 20 20 20 20 28 4d | 56 61 72 20 28 29 29 20 | (M|Var ()) |
|000003c0| 20 20 20 2d 2d 20 63 6f | 6e 73 20 2d 3e 20 70 72 | -- co|ns -> pr|
|000003d0| 6f 64 0a 0a 6e 65 77 43 | 56 61 72 20 3a 3a 20 49 |od..newC|Var :: I|
|000003e0| 4f 20 28 43 56 61 72 20 | 61 29 0a 77 72 69 74 65 |O (CVar |a).write|
|000003f0| 43 56 61 72 20 3a 3a 20 | 43 56 61 72 20 61 20 2d |CVar :: |CVar a -|
|00000400| 3e 20 61 20 2d 3e 20 49 | 4f 20 28 29 0a 72 65 61 |> a -> I|O ().rea|
|00000410| 64 43 56 61 72 20 3a 3a | 20 43 56 61 72 20 61 20 |dCVar ::| CVar a |
|00000420| 2d 3e 20 49 4f 20 61 0a | 0a 6e 65 77 43 56 61 72 |-> IO a.|.newCVar|
|00000430| 20 0a 20 3d 20 6e 65 77 | 45 6d 70 74 79 4d 56 61 | . = new|EmptyMVa|
|00000440| 72 20 3e 3e 3d 20 5c 20 | 64 61 74 75 6d 20 2d 3e |r >>= \ |datum ->|
|00000450| 0a 20 20 20 6e 65 77 4d | 56 61 72 20 28 29 20 20 |. newM|Var () |
|00000460| 20 3e 3e 3d 20 5c 20 61 | 63 6b 20 2d 3e 0a 20 20 | >>= \ a|ck ->. |
|00000470| 20 72 65 74 75 72 6e 20 | 28 43 56 61 72 20 64 61 | return |(CVar da|
|00000480| 74 75 6d 20 61 63 6b 29 | 0a 0a 77 72 69 74 65 43 |tum ack)|..writeC|
|00000490| 56 61 72 20 28 43 56 61 | 72 20 64 61 74 75 6d 20 |Var (CVa|r datum |
|000004a0| 61 63 6b 29 20 76 61 6c | 0a 20 3d 20 74 61 6b 65 |ack) val|. = take|
|000004b0| 4d 56 61 72 20 61 63 6b | 20 20 20 20 20 20 3e 3e |MVar ack| >>|
|000004c0| 20 0a 20 20 20 70 75 74 | 4d 56 61 72 20 64 61 74 | . put|MVar dat|
|000004d0| 75 6d 20 76 61 6c 20 3e | 3e 0a 20 20 20 72 65 74 |um val >|>. ret|
|000004e0| 75 72 6e 20 28 29 0a 0a | 72 65 61 64 43 56 61 72 |urn ()..|readCVar|
|000004f0| 20 28 43 56 61 72 20 64 | 61 74 75 6d 20 61 63 6b | (CVar d|atum ack|
|00000500| 29 0a 20 3d 20 74 61 6b | 65 4d 56 61 72 20 64 61 |). = tak|eMVar da|
|00000510| 74 75 6d 20 3e 3e 3d 20 | 5c 20 76 61 6c 20 2d 3e |tum >>= |\ val ->|
|00000520| 0a 20 20 20 70 75 74 4d | 56 61 72 20 61 63 6b 20 |. putM|Var ack |
|00000530| 28 29 20 3e 3e 20 0a 20 | 20 20 72 65 74 75 72 6e |() >> . | return|
|00000540| 20 76 61 6c 0a 5c 65 6e | 64 7b 63 6f 64 65 7d 0a | val.\en|d{code}.|
+--------+-------------------------+-------------------------+--------+--------+