%!PS (but not EPSF through switch or no memory) %%Creator: dvips by Radical Eye Software %%Title: machuse.dvi %%Pages: 20 -1 %%BoundingBox: 0 0 612 792 %! /TeXDict 200 dict def TeXDict begin /bdf{bind def}def /Inch{Resolution mul} bdf /Dots{72 div Resolution mul}bdf /bop-aux{}bdf /dopage{/page-height exch def /page-width exch def 72 Resolution div dup neg scale translate}bdf /@letter{Resolution dup -10 mul 8.5 11 dopage}bdf /@note{@letter}bdf /@a4{ Resolution dup -10.6929133858 mul 21 2.54 div 29.7 2.54 div dopage}bdf /@translate{translate}bdf /@scale{scale}bdf /@rotate{rotate}bdf /@landscape{[ 0 1 -1 0 0 0]concat Resolution dup 8.5 11 dopage}bdf /@legal{Resolution dup -13 mul 8.5 14 dopage}bdf /@11x17{statusdict /11x17tray known{statusdict begin 11x17tray end}if Resolution dup -16 mul 11 17 dopage}bdf /@manualfeed{ statusdict /manualfeed true put}bdf /@copies{/#copies exch def}bdf /@draft{ /bop-aux{gsave initmatrix 72 dup scale page-width 2 div page-height 2 div translate page-height page-width atan rotate /Helvetica-Bold findfont 2 scalefont setfont(DRAFT)dup stringwidth pop 2 div neg -1 moveto .95 setgray show grestore}bdf}bdf /@FontMatrix[1 0 0 -1 0 0]def /@FontBBox[0 0 1 1]def /dmystr(ZZf@@)def /newname{dmystr cvn}bdf /df{/fontname exch def dmystr 2 fontname cvx(@@@)cvs putinterval newname 7 dict def newname load begin /FontType 3 def /FontMatrix @FontMatrix def /FontBBox @FontBBox def /BitMaps 256 array def /BuildChar{CharBuilder}def /Encoding 256 array def 0 1 255{ Encoding exch /.undef put}for end fontname{/foo setfont}2 array copy cvx def fontname load 0 dmystr 5 string copy cvn cvx put}bdf /dfe{newname newname load definefont setfont}bdf /ch-image{ch-data 0 get}bdf /ch-width{ch-data 1 get} bdf /ch-height{ch-data 2 get}bdf /ch-xoff{ch-data 3 get}bdf /ch-yoff{ch-data 4 get}bdf /ch-tfmw{ch-data 5 get}bdf /CharBuilder{save 3 1 roll exch /BitMaps get exch get /ch-data exch def ch-data null ne{ch-tfmw 0 ch-xoff neg ch-yoff neg ch-width ch-xoff sub ch-height ch-yoff sub setcachedevice ch-width ch-height true[1 0 0 1 ch-xoff ch-yoff]{ch-image}imagemask}if restore}bdf /dc{ /ch-code exch def dup 0 get length 1 lt{pop[<00>1 1 0 0 8.00]}if /ch-data exch def newname load /BitMaps get ch-code ch-data put newname load /Encoding get ch-code dup( )cvs cvn put}bdf /bop{gsave /SaveImage save def /bop-aux load exec 0 0 moveto}bdf /eop{clear SaveImage restore showpage grestore}bdf /@start {/Resolution exch def}bdf /p{show}bdf /RuleMatrix[1 0 0 -1 0 -1]def /BlackDots 8 string def /v{gsave currentpoint translate false RuleMatrix{BlackDots} imagemask grestore}bdf /a{moveto}bdf /delta 0 def /tail{dup /delta exch def 0 rmoveto}bdf /b{exch p tail}bdf /c{p delta 4 sub tail}bdf /d{p delta 3 sub tail }bdf /e{p delta 2 sub tail}bdf /f{p delta 1 sub tail}bdf /g{p delta 0 rmoveto} bdf /h{p delta 1 add tail}bdf /i{p delta 2 add tail}bdf /j{p delta 3 add tail} bdf /k{p delta 4 add tail}bdf /l{p -4 0 rmoveto}bdf /m{p -3 0 rmoveto}bdf /n{ p -2 0 rmoveto}bdf /o{p -1 0 rmoveto}bdf /q{p 1 0 rmoveto}bdf /r{p 2 0 rmoveto }bdf /s{p 3 0 rmoveto}bdf /t{p 4 0 rmoveto}bdf /w{0 rmoveto}bdf /x{0 exch rmoveto}bdf /y{3 -1 roll p moveto}bdf /bos{/section save def}bdf /eos{clear section restore}bdf /SDict 200 dict def SDict begin /@SpecialDefaults{/hs 8.5 Inch def /vs 11 Inch def /ho 0 def /vo 0 def /hsc 1 def /vsc 1 def /ang 0 def /CLIP false def /BBcalc false def}bdf /@hsize{/hs exch def /CLIP true def}bdf /@vsize{/vs exch def /CLIP true def}bdf /@hoffset{/ho exch def}bdf /@voffset{ /vo exch def}bdf /@hscale{@scaleunit div /hsc exch def}bdf /@vscale{ @scaleunit div /vsc exch def}bdf /@angle{/ang exch def rotate}bdf /@scaleunit 1 def /@rwi{10 div /rwi exch def}bdf /@llx{/llx exch def}bdf /@lly{/lly exch def}bdf /@urx{/urx exch def}bdf /@ury{/ury exch def /BBcalc true def}bdf /@setclipper{BBcalc{rwi urx llx sub div dup scale llx neg lly neg translate}{ hsc vsc scale}ifelse CLIP{newpath 0 0 moveto hs 0 rlineto 0 vs rlineto hs neg 0 rlineto closepath clip}{initclip}ifelse}bdf end /@MacSetUp{userdict /md known{userdict /md get type /dicttype eq{md begin /letter{}def /note{}def /legal{}def /od{txpose 1 0 mtx defaultmatrix dtransform exch atan/pa exch def newpath clippath mark{transform{itransform moveto}}{transform{itransform lineto}}{6 -2 roll transform 6 -2 roll transform 6 -2 roll transform{ itransform 6 2 roll itransform 6 2 roll itransform 6 2 roll curveto}}{{ closepath}}pathforall newpath counttomark array astore /gc xdf pop ct 39 0 put 10 fz 0 fs 2 F/|______Courier fnt invertflag{PaintBlack}if}def /txpose{pxs pys scale ppr aload pop por{noflips{pop exch neg exch translate pop 1 -1 scale}if xflip yflip and{pop exch neg exch translate 180 rotate 1 -1 scale ppr 3 get ppr 1 get neg sub neg ppr 2 get ppr 0 get neg sub neg translate}if xflip yflip not and{pop exch neg exch translate pop 180 rotate ppr 3 get ppr 1 get neg sub neg 0 translate}if yflip xflip not and{ppr 1 get neg ppr 0 get neg translate} if}{noflips{translate pop pop 270 rotate 1 -1 scale}if xflip yflip and{ translate pop pop 90 rotate 1 -1 scale ppr 3 get ppr 1 get neg sub neg ppr 2 get ppr 0 get neg sub neg translate}if xflip yflip not and{translate pop pop 90 rotate ppr 3 get ppr 1 get neg sub neg 0 translate}if yflip xflip not and{ translate pop pop 270 rotate ppr 2 get ppr 0 get neg sub neg 0 exch translate} if}ifelse scaleby96{ppr aload pop 4 -1 roll add 2 div 3 1 roll add 2 div 2 copy translate .96 dup scale neg exch neg exch translate}if}def /cp{pop pop showpage pm restore}def end}if}if}def /psf$TeXscale{65536 div}def /startTexFig {/psf$SavedState save def userdict maxlength dict begin Resolution 72 div dup neg scale currentpoint translate /psf$ury exch psf$TeXscale def /psf$urx exch psf$TeXscale def /psf$lly exch psf$TeXscale def /psf$llx exch psf$TeXscale def /psf$y exch psf$TeXscale def /psf$x exch psf$TeXscale def currentpoint /psf$cy exch def /psf$cx exch def /psf$sx psf$x psf$urx psf$llx sub div def /psf$sy psf$y psf$ury psf$lly sub div def psf$sx psf$sy scale psf$cx psf$sx div psf$llx sub psf$cy psf$sy div psf$ury sub translate /showpage{}def /erasepage{ }def /copypage{}def @MacSetUp}def /doclip{psf$llx psf$lly psf$urx psf$ury currentpoint 6 2 roll newpath 4 copy 4 2 roll moveto 6 -1 roll exch lineto exch lineto exch lineto closepath clip newpath moveto}def /endTexFig{end psf$SavedState restore}def /@beginspecial{SDict begin /SpecialSave save def gsave Resolution 72 div dup neg scale currentpoint translate @SpecialDefaults} bdf /@setspecial{ho vo translate @setclipper /showpage{}def newpath}bdf /@endspecial{grestore clear SpecialSave restore end}bdf /@defspecial{SDict begin}bdf /@fedspecial{end}bdf /li{lineto}bdf /rl{rlineto}bdf /rc{rcurveto} bdf /np{/SaveX currentpoint /SaveY exch def def newpath}bdf /st{stroke SaveX SaveY moveto}bdf /fil{fill SaveX SaveY moveto}bdf /ellipse{/endangle exch def /startangle exch def /yrad exch def /xrad exch def /savematrix matrix currentmatrix def translate xrad yrad scale 0 0 1 startangle endangle arc savematrix setmatrix}bdf end %! TeXDict begin /ReEncodeForTeX{findfont /basefontdict exch def /newfont basefontdict maxlength 2 add dict def basefontdict{exch dup /FID ne{dup /Encoding eq{exch dup length array copy}{exch}ifelse newfont 3 1 roll put}{ pop pop}ifelse}forall normalvec fixup basefontdict /FontInfo get /isFixedPitch get{courvec fixup}if 256 dict begin newfont /Encoding get 0 1 255{2 copy get 3 index 2 index get 1000 mul ptsize div def pop}for pop pop newfont /Metrics currentdict put end newname newfont definefont}bind def /fixup{aload length 2 idiv{dup newfont /CharStrings get exch known{newfont /Encoding get 3 1 roll put}{pop pop}ifelse}repeat}bind def /normalvec[0 /Gamma 1 /Delta 2 /Theta 3 /Lambda 4 /Xi 5 /Pi 6 /Sigma 7 /Upsilon 8 /Phi 9 /Psi 10 /Omega 12 /fi 13 /fl 16 /dotlessi 18 /grave 19 /acute 20 /caron 21 /breve 22 /macron 23 /ring 24 /cedilla 25 /germandbls 26 /ae 27 /oe 28 /oslash 29 /AE 30 /OE 31 /Oslash 34 /quotedblright 60 /exclamdown 62 /questiondown 92 /quotedblleft 94 /circumflex 95 /dotaccent 123 /endash 124 /emdash 125 /quotedbl 126 /tilde 127 /dieresis] def /courvec[11 /arrowup 12 /arrowdown 13 /quotesingle 14 /exclamdown 15 /questiondown 34 /quotedbl 60 /less 62 /greater 92 /backslash 95 /underscore 123 /braceleft 124 /bar 125 /braceright]def /pf{exch pop 655360 div mul Resolution mul 7227 div /ptsize exch def /PSname exch def exch /TeXname exch def dmystr 2 TeXname cvx(@@@)cvs putinterval PSname ReEncodeForTeX newname exch[ptsize 0 0 ptsize neg 0 0]makefont def TeXname{/foo setfont}2 array copy cvx def TeXname load 0 dmystr 5 string copy cvn cvx put}bind def /ObliqueFont{ /ObliqueAngle exch def /ObliqueBaseName exch def /ObliqueFontName exch def /ObliqueTransform[1 0 ObliqueAngle sin ObliqueAngle cos div 1 0 0]def /basefontdict ObliqueBaseName findfont ObliqueTransform makefont def /newfont basefontdict maxlength dict def basefontdict{exch dup /FID ne{dup /Encoding eq {exch dup length array copy newfont 3 1 roll put}{exch newfont 3 1 roll put} ifelse}{pop pop}ifelse}forall newfont /FontName ObliqueFontName put ObliqueFontName newfont definefont pop}bind def /CopyFont{findfont dup length dict /newfont exch def{1 index /FID ne{newfont 3 1 roll put}{pop pop}ifelse} forall newfont /FontName 2 index put newfont definefont pop}bind def /SmallCapsFont{/SmallCapsBaseName exch def /SmallCapsFontName exch def /basefontdict SmallCapsBaseName findfont def /newfont basefontdict maxlength 10 add dict def newfont begin /FontName SmallCapsFontName def /FontBaseDict basefontdict 1000 scalefont def /FontSCDict FontBaseDict .8 scalefont def /FontType 3 def /BuildChar{SmallCapChar}def /FontMatrix dup basefontdict exch get def /FontBBox dup basefontdict exch get def /Encoding dup basefontdict exch get def /CharStrings dup basefontdict exch get def /FontInfo dup basefontdict exch get def end SmallCapsFontName newfont definefont pop}bind def /SmallCapChar{/achar(A)def achar exch 0 exch put begin achar 0 get dup 97 ge exch 122 le and{achar 0 achar 0 get 32 sub put FontSCDict}{FontBaseDict} ifelse setfont achar stringwidth FontBBox setcachedevice newpath 0 0 moveto achar show end}bind def end TeXDict begin 300 @start bos /fa [ 0 0 0 0 0 0 0 0 0 0 0 0 33 33 0 0 17 0 20 20 20 20 20 20 20 33 43 43 30 60 60 47 15 20 30 30 30 60 50 20 20 20 30 34 15 20 15 17 30 30 30 30 30 30 30 30 30 30 20 20 20 34 30 30 56 43 40 43 43 40 37 47 47 23 30 47 40 56 43 47 37 47 43 33 40 43 43 60 43 43 40 20 30 20 20 20 20 30 33 27 33 27 20 30 33 17 20 33 17 50 33 30 33 33 27 23 20 33 30 43 30 30 27 30 60 20 20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 30 30 10 30 30 30 30 17 30 30 20 20 33 33 0 30 30 30 15 0 32 21 20 30 30 30 60 60 0 30 0 20 20 20 20 20 20 20 20 0 20 20 0 20 20 20 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60 0 18 0 0 0 0 40 47 60 20 0 0 0 0 0 43 0 0 0 17 0 0 17 30 43 33 0 0 0 0 ] /Times-Bold 1000 655360 943718 pf /fb [ 0 0 0 0 0 0 0 0 0 0 0 0 28 28 0 0 14 0 17 17 17 17 17 17 17 28 36 36 25 50 50 39 12 17 25 25 25 50 41 17 17 17 25 28 12 17 12 14 25 25 25 25 25 25 25 25 25 25 17 17 17 28 25 25 46 36 33 36 36 33 30 39 39 19 25 39 33 47 36 39 30 39 36 28 33 36 36 50 36 36 33 17 25 17 17 17 17 25 28 22 28 22 17 25 28 14 17 28 14 41 28 25 28 28 22 19 17 28 25 36 25 25 22 25 50 17 17 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 25 25 8 25 25 25 25 14 25 25 17 17 28 28 0 25 25 25 12 0 27 17 17 25 25 25 50 50 0 25 0 17 17 17 17 17 17 17 17 0 17 17 0 17 17 17 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50 0 15 0 0 0 0 33 39 50 16 0 0 0 0 0 36 0 0 0 14 0 0 14 25 36 28 0 0 0 0 ] /Times-Bold 1000 655360 786432 pf /fc [ 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 25 0 0 25 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 0 0 25 0 25 25 25 25 25 25 25 25 0 25 25 0 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 25 25 0 25 0 0 0 0 0 0 0 0 0 25 0 0 25 25 0 25 0 0 0 0 ] /Courier 1000 655360 655360 pf /fd [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 12 0 14 14 14 14 14 14 14 21 28 28 21 37 39 30 10 14 23 21 21 35 32 14 14 14 21 28 10 14 10 12 21 21 21 21 21 21 21 21 21 21 14 14 16 28 21 21 38 25 25 28 30 25 25 30 30 14 18 28 23 35 28 30 25 30 25 21 23 30 25 35 25 23 23 16 23 16 14 14 14 21 21 18 21 18 12 21 21 12 12 18 12 30 21 21 21 21 16 16 12 21 18 28 18 18 16 21 37 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 21 21 7 21 21 21 21 9 23 21 14 14 21 21 0 21 21 21 10 0 22 15 14 23 23 21 37 42 0 21 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 23 30 39 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 28 21 0 0 0 0 ] /Times-Italic 1000 655360 655360 pf /fe [ 0 0 0 0 0 0 0 0 0 0 0 0 23 23 0 0 12 0 14 14 14 14 14 14 14 21 28 30 21 37 37 30 10 14 18 21 21 35 32 14 14 14 21 23 10 14 10 12 21 21 21 21 21 21 21 21 21 21 12 12 14 23 18 18 38 30 28 28 30 25 23 30 30 14 16 30 25 37 30 30 23 30 28 23 25 30 30 39 30 30 25 14 18 14 14 14 14 18 21 18 21 18 14 21 21 12 12 21 12 32 21 21 21 21 14 16 12 21 21 30 21 21 18 21 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 21 21 7 21 21 21 21 7 18 21 14 14 23 23 0 21 21 21 10 0 19 15 14 18 18 21 42 42 0 18 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 25 30 37 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 30 21 0 0 0 0 ] /Times-Roman 1000 655360 655360 pf /ff [ 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 22 22 0 22 22 22 22 22 22 22 22 0 0 22 0 0 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 22 22 22 22 22 22 22 22 22 22 22 22 0 0 0 22 22 22 22 0 22 22 22 22 22 22 22 0 0 22 0 22 22 22 22 22 22 22 22 0 22 22 0 22 22 22 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 0 0 0 0 22 22 0 22 0 0 0 0 0 0 0 0 0 22 0 0 22 22 0 22 0 0 0 0 ] /Courier 1000 655360 589824 pf end TeXDict begin @letter %%Page: 18 1 bop 150 162 a fe(18)950 b fd(4)41 b(GENERAL)12 b(MACH)e(INFORMA)n(TION)150 307 y fb(4.5)50 b(Mach)12 b(Include)g(Files)150 385 y fe(When)d(writing)d(a)j (program)f(that)g(uses)h(Mach)f(facilities)g(some)h(of)f(the)g(following)e (include)i(\014les)g(may)h(be)g(needed:)240 472 y ff(mach.h)25 b(:)d(needed)j (for)f(all)g(Mach)g(programs)240 518 y(mach/messa)q(ge)q(.h)i(:)d(if)g(any)h (message)h(structure)q(s)h(are)d(used)240 563 y(mach_error)q(.h)j(:)d(if)g (mach_erro)q(r\()q(\))j(is)d(used)240 609 y(servers/en)q(v_)q(mgr)q(.h)j(:)d (if)g(environm)q(ent)j(manager)g(server)e(is)g(used)240 655 y(servers/ne)q (tn)q(ame)q(.h)i(:)d(if)g(netname)j(server)e(is)g(used)240 700 y(cthreads.h)i (:)d(if)g(C)g(threads)i(package)h(is)d(used)150 873 y fb(4.6)50 b(Mach)12 b (Information/Questions)150 951 y fe(A)e(Mach)g(news)g(group)e(exists)i(to)f (keep)h(the)f(user)h(community)f(up)g(to)g(date)h(on)f(new)h(Mach)g(releases.) 17 b(This)10 b(news)150 1000 y(group)f(is)h(called)h(`comp.os.mach'.)212 1050 y(If)18 b(you)f(have)h(questions)f(relating)g(to)g(the)h(use)g(of)f(any)h(Mac\ h)h(facilities,)g(or)e(any)h(comments)h(on)e(this)150 1100 y(tutorial,)12 b (send)i(mail)f(to)g fc(machlib@wb1.cs.cmu.edu)p fe(.)22 b(Comments)14 b(on)f (this)f(tutorial)f(will)h(be)i(greatly)150 1150 y(appreciated.)g eop %%Page: 17 2 bop 1758 162 a fe(17)150 307 y fa(4)60 b(General)12 b(Mach)k(Information)150 419 y fb(4.1)50 b(Structur)o(e)11 b(of)h(the)g(Mach)g(T)l(r)o(ee)150 503 y fe (Directories)e(of)g(interest)f(include:)240 650 y ff(/usr/mach/)q(ma)q(n)25 b (:)e(Mach)h(manual)h(pages)240 696 y(/usr/mach/)q(bi)q(n)g(:)e(Mach)h(system) h(programs)h(such)e(as)f(MiG)240 741 y(/usr/mach/)q(et)q(c)i(:)e(Mach)h(serve\ rs)i(such)e(as)f(the)h(environmen)q(t)i(manager)240 787 y(/usr/mach/)q(in)q (clu)q(de)g(:)d(Mach)h(include)h(files)240 833 y(/usr/mach/)q(li)q(b)g(:)e (Mach)h(librarie)q(s)i(such)e(as)f(libmach.a)j(and)e(libthreads)q(.a)150 1090 y fb(4.2)50 b(Wher)o(e)12 b(to)g(Find)h(Examples)g(and)e(Manuals)150 1179 y fe (Y)l(ou)k(can)g(print)f(copies)h(of)g(the)g(Mach)g(manuals)h(and)f(documents) g(for)g(yourself)f(using)g(the)h(.ps)g(\014les)h(in)e(the)150 1228 y fc(/usr/\ mach/doc)7 b fe(directory)m(.)15 b(There)9 b(is)f(subdirectory)f fc(examples) h fe(in)f fc(doc)i fe(which)e(contains)h(the)g(example)150 1278 y(programs)j (used)g(in)f(the)h(two)f(tutorial)f(documents.)18 b(See)12 b(the)f fc(lpr)g fe (UNIX)f(manual)i(entry)e(on)g(how)h(to)f(print)g(.ps)150 1328 y(\014les.)150 1477 y fb(4.3)50 b(Setting)11 b(Up)h(Sear)o(ch)g(Paths)150 1566 y fe(T)m(o)i (compile)f(or)g(load)g(a)h(Mach)g(program)f(your)f(paths)h(must)h(be)f(set)h (to)f(look)f(in)h(the)g(proper)g(place)h(for)e(Mach)150 1616 y(include)g(\014\ les)g(and)h(libraries.)21 b(By)12 b(typing)e fc(source)27 b(/usr/mach/lib/mac\ hpaths)10 b fe(the)i(appropriate)150 1665 y(Mach)f(directories)e(will)g(be)i (added)g(to)e(your)h(existing)f(paths.)150 1815 y fb(4.4)50 b(Mach)12 b(Libra\ ries)150 1903 y fe(The)i(Mach)h(library)m(,)e(-lmach,)j(must)d(be)h(loaded)g (with)e(most)i(of)f(the)g(examples)i(given)e(in)g(this)g(tutorial.)24 b(Any) 150 1953 y(program)11 b(using)f(Mach)i(kernel)e(interface)i(functions)d(must) i(be)h(loaded)e(with)g(libmach)h(and)g(the)g(Mach)h(version)150 2003 y(of)f fc (crt0)p fe(.)19 b(For)11 b(example,)i(assuming)e(that)g(/usr/mach/lib)e(is)j (on)f(your)f(LP)l(A)-5 b(TH)13 b(before)f(any)f(other)g(version)f(of)150 2053 y fc(crt0)p fe(:)262 2168 y ff(cc)23 b(-o)h(simp_ipc)h(simp_ipc)q(.c)h(-lmach) 212 2300 y fe(T)m(wo)15 b(threads)e(libraries)h(exist:)22 b(libthreads.a)13 b (and)h(libco)p fc(_)p fe(threads.a.)27 b(The)14 b('co')g(version)g(of)f(this) g(library)150 2350 y(works)k(on)h(all)f(current)g(Mach)i(kernels.)38 b(This) 17 b(version)g(does)h(not)f(actually)g(use)h(Mach)h(threads;)i(it)c(uses)150 2399 y(coroutines.)k(This)12 b(library)f(does)h(not)g(provide)f(real)i(parall\ elism,)f(a)h(single)f(UNIX)g(process)g(is)g(running.)20 b(The)150 2449 y(othe\ r)10 b(threads)g(library)m(,)g(libthreads.a,)g(uses)h(Mach)g(threads.)g eop %%Page: 16 3 bop 150 162 a fe(16)757 b fd(3)41 b(MIG)10 b(-)g(THE)h(MACH)f(INTERF)-5 b (ACE)11 b(GENERA)n(T)o(OR)329 307 y ff({)509 353 y(j)22 b(=)h(\(\(int\)ra)q (ndo)q(m\()q(\)%)q(ran)q(ge)q(\))i(+)e(\(int\)')i(';)509 399 y(password[i)q (])h(=)c(\(char\)j;)329 444 y(})329 490 y(password)q([25)q(])k(=)d('\\0';)329 535 y(return\(K)q(ERN)q(_S)q(UC)q(CES)q(S\))q(;)150 581 y(})150 732 y fb(3.5) 50 b(User)13 b(Side)150 821 y fe(The)e(following)d(code)i(shows)h(an)f(exampl\ e)h(of)f(how)g(to)g(use)g(the)h(server)n(.)150 937 y ff(/*)23 b(This)h(is)g (an)f(example)i(of)e(a)g(program)j(using)e(the)g(random)h(server)g(*/)150 983 y(#include)h()150 1028 y(#include)g() 150 1074 y(#include)g("random.h")150 1120 y(#include)g() 150 1165 y(#include)g()150 1302 y(main\(\))150 1348 y({)240 1394 y (int)203 b(number;)240 1439 y(string25)93 b(password;)240 1485 y(port_t)137 b (serv_port;)240 1531 y(kern_retur)q(n_)q(t)25 b(retcode;)329 1622 y(printf\(") q(Loo)q(ki)q(ng)h(up)d(port)h(for)g(random)h(server\\n")q(\);)329 1668 y(retc\ ode)h(=)c(netname_)q(lo)q(ok_)q(up)q(\(n)q(ame)q(_s)q(erv)q(er)q(_p)q(ort)q (,")q(",")q(Ra)q(nd)q(omS)q(er)q(ver)q(Po)q(rt)q(",)688 1713 y(&serv_por)q (t\))q(;)329 1759 y(if)i(\(retcode)h(!=)f(KERN_SUCCE)q(SS)q(\))329 1805 y({) 90 b(mach_err)q(or)q(\("e)q(rr)q(or)26 b(in)d(looking)i(up)f(port)g(for)f(ran\ dom)i(server",)q(re)q(tco)q(de)q(\);)441 1850 y(printf\(")q(Ra)q(ndo)q(m)h (server)f(may)e(not)h(be)f(running\\n)q("\))q(;)441 1896 y(exit\(\);)329 1941 y(})329 1987 y(printf\(")q(Cal)q(li)q(ng)j(get_rando)q(m\\)q(n"\))q(;)329 2033 y(retcode)g(=)c(get_rand)q(om)q(\(se)q(rv)q(_p)q(ort)q(,&)q(num)q(be)q(r\))q (;)329 2078 y(if)i(\(retcode)h(==)f(KERN_SUCCE)q(SS)q(\))509 2124 y(printf\("\ Re)q(su)q(lt)i(from)e(get_rando)q(m)i(is)d(%d\\n",num)q(ber)q(\);)329 2170 y (else)h(mach_err)q(or)q(\("E)q(rr)q(or)i(from)e(get_rando)q(m)i(is",retcod)q (e\))q(;)329 2215 y(printf\(")q(Cal)q(li)q(ng)g(get_secre)q(t\\)q(n"\))q(;) 329 2261 y(retcode)g(=)c(get_secr)q(et)q(\(se)q(rv)q(_p)q(ort)q(,p)q(ass)q (wo)q(rd)q(\);)329 2307 y(if)i(\(retcode)h(==)f(KERN_SUCCE)q(SS)q(\))509 2352 y(printf\("Re)q(su)q(lt)i(from)e(get_secre)q(t)i(is)d(%s\\n",pas)q(swo)q(rd)q (\);)329 2398 y(else)h(mach_err)q(or)q(\("E)q(rr)q(or)i(from)e(get_secre)q (t)i(is",retcod)q(e\))q(;)150 2444 y(})g eop %%Page: 15 4 bop 150 162 a fd(3.4)41 b(Server)12 b(pr)n(ocedur)n(es)1214 b fe(15)329 307 y ff(msg_simp)q(le)26 b(=)d(In0P->Head)q(.m)q(sg)q(_si)q(mp)q(le;)329 353 y(if) h(\(\(msg_size)i(!=)d(24\))h(||)f(\(msg_sim)q(ple)j(!=)e(TRUE\)\))509 399 y ({)e(OutP->Re)q(tC)q(ode)k(=)d(MIG_BAD_A)q(RG)q(UM)q(ENT)q(S;)j(return;)f(}) 240 444 y(#endif)g(TypeCheck)329 535 y(OutP->Re)q(tCo)q(de)h(=)d(get_rando)q (m\()q(In0)q(P-)q(>He)q(ad)q(.m)q(sg_)q(re)q(que)q(st)q(_p)q(ort)q(,)j(&OutP-\ >num)q(\);)329 581 y(if)e(\(OutP->Ret)q(Co)q(de)i(!=)d(KERN_SUCC)q(ES)q(S\)) 509 627 y(return;)329 718 y(msg_size)j(=)d(40;)329 809 y(OutP->nu)q(mTy)q(pe) j(=)d(numType;)329 855 y(OutP->He)q(ad.)q(ms)q(g_)q(sim)q(pl)q(e)i(=)e(TRUE;) 329 901 y(OutP->He)q(ad.)q(ms)q(g_)q(siz)q(e)j(=)c(msg_size)q(;)240 946 y(}) 150 1147 y fb(3.4)50 b(Server)13 b(pr)o(ocedur)o(es)150 1224 y fe(Finally)d (the)i(subsystem)g(implementor)f(must)g(write)h(the)f(proceedures)h(that)g (actually)f(perform)g(the)h(requested)150 1274 y(operations.)j(For)10 b(this) f(server)i(the)f(following)e(code)j(will)e(do.)150 1353 y ff(/*)23 b(procedue) q(s)i(of)f(random_ser)q(ve)q(r)h(*/)150 1399 y(#include)h()150 1445 y (#include)g("random_ty)q(pe)q(s.)q(h")150 1536 y(long)91 b(random\(\))q(;)150 1673 y(kern_retu)q(rn)q(_t)26 b(get_rando)q(m\(s)q(er)q(v_p)q(or)q(t,)q(num)q (\))150 1719 y(/*)d(get_rand)q(om)j(returns)f(a)e(random)i(number)g(between)g (0)e(and)h(2**32)g(-)f(1)g(*/)240 1764 y(port_t)137 b(serv_port;)240 1810 y (int)203 b(*num;)150 1856 y({)329 1901 y(*num)24 b(=)f(\(int\))i(random\(\);) 329 1947 y(return\(K)q(ERN)q(_S)q(UC)q(CES)q(S\))q(;)150 1993 y(})150 2084 y (kern_retu)q(rn)q(_t)h(get_secre)q(t\(s)q(er)q(v_p)q(or)q(t,)q(pas)q(sw)q(ord) q(\))240 2130 y(port_t)137 b(serv_port;)240 2175 y(string25)93 b(password;) 150 2221 y(/*)23 b(get_secr)q(et)j(returns)f(a)e(random)i(printable)h(ascii)f (string)f(25)g(chars)g(long)g(*/)150 2267 y({)240 2312 y(int)203 b(i,j;)240 2358 y(int)g(range)24 b(=)f(\(int\)'~')j(-)d(\(int\)')h(';)329 2449 y(for)g (\(i=0;i<25)q(;)i(i++\))g eop %%Page: 14 5 bop 150 162 a fe(14)757 b fd(3)41 b(MIG)10 b(-)g(THE)h(MACH)f(INTERF)-5 b (ACE)11 b(GENERA)n(T)o(OR)329 307 y ff(return)25 b(TRUE;)240 353 y(})212 489 y fe(The)17 b(two)e(internal)g(routines)f(that)i(do)f(most)h(of)f(the)h(message) i(unpacking)d(are)h fc(_Xget_random)f fe(and)150 539 y fc(_Xget_secret)p fe (.)33 b(These)17 b(routines)f(respectively)f(call)i fc(get_random)e fe(and)i fc(get_secret)e fe(with)g(the)150 589 y(appropriate)e(parameters.)26 b(When) 13 b(those)g(routines)g(return,)g(a)h(reply)f(message)i(is)e(created)i(in)d (the)i(buf)o(fer)f(that)150 639 y fc(OutHeadP)d fe(points)f(to.)212 684 y(The) i(following)d(is)i(the)g(code)h(for)f fc(_Xget_random)p fe(;)240 805 y ff(/*) 23 b(Routine)i(get_rand)q(om)h(*/)240 851 y(mig_intern)q(al)g(novalue)f(_Xget\ _ra)q(nd)q(om\()q(In)q(Hea)q(dP)q(,)h(OutHeadP\))329 897 y(msg_head)q(er_)q (t)g(*InHeadP,)g(*OutHeadP)q(;)240 942 y({)329 988 y(typedef)g(struct)f({)509 1034 y(msg_header)q(_t)h(Head;)329 1079 y(})d(Request;)329 1171 y(typedef)j (struct)f({)509 1216 y(msg_header)q(_t)h(Head;)509 1262 y(msg_type_t)g(RetCod\ eT)q(ype)q(;)509 1308 y(kern_retur)q(n_)q(t)f(RetCode;)509 1353 y(msg_type_t) h(numType;)509 1399 y(int)d(num;)329 1445 y(})g(Reply;)329 1536 y(register)j (Request)f(*In0P)g(=)e(\(Request)i(*\))f(InHeadP;)329 1582 y(register)i(Reply) f(*OutP)f(=)f(\(Reply)i(*\))e(OutHeadP;)329 1627 y(extern)i(kern_ret)q(urn)q (_t)h(get_rando)q(m\()q(\);)240 1719 y(#if)d(TypeChec)q(k)329 1764 y(boolean_) q(t)i(msg_simp)q(le)q(;)240 1810 y(#endif)g(TypeCheck)329 1901 y(unsigned)h (int)e(msg_size;)329 1993 y(static)h(msg_type)q(_t)h(numType)f(=)e({)509 2038 y(/*)g(msg_type_)q(nam)q(e)j(=)d(*/)247 b(MSG_TYPE_)q(IN)q(TEG)q(ER)q(_32)q (,)509 2084 y(/*)23 b(msg_type_)q(siz)q(e)j(=)d(*/)247 b(32,)509 2130 y(/*)23 b(msg_type_)q(num)q(be)q(r)j(=)c(*/)203 b(1,)509 2175 y(/*)23 b(msg_type_)q (inl)q(in)q(e)j(=)c(*/)203 b(TRUE,)509 2221 y(/*)23 b(msg_type_)q(lon)q(gf)q (or)q(m)i(=)e(*/)158 b(FALSE,)509 2267 y(/*)23 b(msg_type_)q(dea)q(ll)q(oc)q (ate)j(=)d(*/)113 b(FALSE,)509 2312 y(/*)23 b(msg_type_)q(unu)q(se)q(d)j(=)c (*/)i(0)329 2358 y(};)240 2403 y(#if)f(TypeChec)q(k)329 2449 y(msg_size)j(=)d (In0P->Hea)q(d.m)q(sg)q(_s)q(ize)q(;)g eop %%Page: 13 6 bop 150 162 a fd(3.3)41 b(Server)12 b(message)f(dispatch)e(code)1016 b fe (13)150 307 y fb(3.3)50 b(Server)13 b(message)g(dispatch)f(code)150 389 y fe (The)h(\014le)g fc(randomServer.c)f fe(contains)g(the)h(server)g(side)f(code) i(that)e(was)h(generated)g(by)g(MIG.)g(It)f(exports)150 435 y(the)j(routine)f fc(random_server)h fe(that)f(is)i(called)f(by)g(the)h(main)f(program.)31 b (It)15 b(checks)h(the)g(message)h(id)e(to)150 480 y(determine)f(what)f(messag\ e)j(was)e(received,)i(and)e(then)f(unpacks)h(the)g(ar)o(guments)g(and)f(calls) h(the)g(appropriate)150 526 y(server)d(procedure.)16 b(The)11 b(following)c (fragment)k(shows)f(the)g(control)f(logic)g(of)h(the)g(dispatch)g(routine.) 240 668 y ff(boolean_t)26 b(random_se)q(rve)q(r\()q(InH)q(ea)q(dP)q(,)f(OutHe\ adP)q(\))329 714 y(msg_head)q(er_)q(t)h(*InHeadP,)g(*OutHeadP)q(;)240 760 y ({)329 805 y(register)g(msg_heade)q(r_)q(t)f(*InP)g(=)45 b(InHeadP;)329 851 y (register)26 b(death_pil)q(l_)q(t)f(*OutP)g(=)e(\(death_pi)q(ll_)q(t)j(*\))d (OutHeadP;)329 942 y(static)i(msg_type)q(_t)h(RetCodeTy)q(pe)g(=)d({)509 988 y (/*)g(msg_type_)q(nam)q(e)j(=)d(*/)247 b(MSG_TYPE_)q(IN)q(TEG)q(ER)q(_32)q (,)509 1034 y(/*)23 b(msg_type_)q(siz)q(e)j(=)d(*/)247 b(32,)509 1079 y(/*)23 b(msg_type_)q(num)q(be)q(r)j(=)c(*/)203 b(1,)509 1125 y(/*)23 b(msg_type_)q (inl)q(in)q(e)j(=)c(*/)203 b(TRUE,)509 1171 y(/*)23 b(msg_type_)q(lon)q(gf)q (or)q(m)i(=)e(*/)158 b(FALSE,)509 1216 y(/*)23 b(msg_type_)q(dea)q(ll)q(oc)q (ate)j(=)d(*/)113 b(FALSE,)509 1262 y(/*)23 b(msg_type_)q(unu)q(se)q(d)j(=)c (*/)i(0)329 1308 y(};)329 1399 y(OutP->He)q(ad.)q(ms)q(g_)q(sim)q(pl)q(e)h (=)e(TRUE;)329 1445 y(OutP->He)q(ad.)q(ms)q(g_)q(siz)q(e)j(=)c(sizeof)j(*OutP\ ;)329 1490 y(OutP->He)q(ad.)q(ms)q(g_)q(typ)q(e)h(=)c(InP->msg)q(_t)q(ype)q (;)329 1536 y(OutP->He)q(ad.)q(ms)q(g_)q(loc)q(al)q(_po)q(rt)k(=)d(PORT_NULL) q(;)329 1582 y(OutP->He)q(ad.)q(ms)q(g_)q(rem)q(ot)q(e_p)q(or)q(t)j(=)c(InP->\ msg)q(_r)q(epl)q(y_)q(por)q(t;)329 1627 y(OutP->He)q(ad.)q(ms)q(g_)q(id)k(=)d (InP->msg_i)q(d)j(+)c(100;)329 1673 y(OutP->Re)q(tCo)q(de)q(Ty)q(pe)k(=)d(Ret\ CodeTyp)q(e;)329 1719 y(OutP->Re)q(tCo)q(de)j(=)d(MIG_BAD_I)q(D;)329 1810 y (if)h(\(\(InP->msg)q(_i)q(d)h(>)e(501\))h(||)g(\(InP->msg_)q(id)i(<)d(500\)\)) 509 1856 y(return)i(FALSE;)329 1901 y(else)f({)509 1947 y(typedef)h(novalue)g (\(*SERVER)q(_ST)q(UB)q(_P)q(ROC)q(\)\()q(\);)509 2038 y(static)g(SERVER_STU) q(B_)q(PRO)q(C)h(routines[])g(=)d({)688 2084 y(_Xget_ran)q(do)q(m,)688 2130 y (_Xget_sec)q(re)q(t,)509 2175 y(};)509 2267 y(if)g(\(routines)q([In)q(P-)q (>m)q(sg_)q(id)j(-)d(500]\))688 2312 y(\(routines)q([I)q(nP-)q(>m)q(sg_)q(id) j(-)d(500]\))h(\(InP,)h(&OutP->He)q(ad)q(\);)531 2358 y(else)688 2403 y(retur\ n)g(FALSE;)329 2449 y(})g eop %%Page: 12 7 bop 150 162 a fe(12)757 b fd(3)41 b(MIG)10 b(-)g(THE)h(MACH)f(INTERF)-5 b (ACE)11 b(GENERA)n(T)o(OR)329 307 y ff(msg_head)q(er_)q(t)26 b(*request)f(=)e (\(msg_hea)q(der)q(_t)j(*\))d(requestb)q(uf)q(;)329 353 y(death_pi)q(ll_)q (t)j(*reply)f(=)d(\(death_p)q(il)q(l_t)k(*\))e(replybuf;)329 399 y(msg_retu)q (rn_)q(t)i(mr;)329 490 y(/*)352 535 y(*)45 b(Problems)26 b(with)e(this)g(serv\ er)h(loop:)352 581 y(*)135 b(Requests)25 b(which)g(are)f(not)f(processe)q(d)i (successf)q(ul)q(ly)352 627 y(*)135 b(\(bad)24 b(msg_id,)h(type)f(mismatch,)i (whatever)q(\))f(should)352 672 y(*)135 b(be)23 b(cleaned)i(up;)f(ports)g(&)f (memory)i(should)g(be)e(dealloca)q(ted)q(.)352 718 y(*)352 764 y(*)135 b(Repl\ ies)25 b(which)f(are)g(dropped)h(\(reply)g(port)f(died)h(or)e(was)352 809 y (*)135 b(full,)24 b(some)g(problem)i(with)e(rights)h(or)e(memory)i(in)e(the)h (reply\))352 855 y(*)135 b(should)25 b(also)f(be)f(cleaned)i(up.)352 901 y (*)45 b(But)24 b(these)g(are)g(hard)g(problems)i(\(harder)f(than)f(they)g(mig\ ht)h(appear\))352 946 y(*)45 b(so)23 b(we)g(ignore)i(them.)352 992 y(*/)329 1083 y(for)f(\(;;\))g({)509 1129 y(/*)f(receive)i(a)e(request)i(message)h(*/) 509 1220 y(request->m)q(sg)q(_si)q(ze)g(=)d(sizeof)i(requestbu)q(f;)509 1266 y (request->m)q(sg)q(_lo)q(ca)q(l_)q(por)q(t)h(=)c(service;)509 1357 y(mr)h(=)g (msg_receiv)q(e\()q(re)q(que)q(st)q(,)i(MSG_OPTI)q(ON)q(_NO)q(NE)q(,)h(0\);) 509 1403 y(if)d(\(mr)h(!=)f(RCV_SUCCE)q(SS\))688 1449 y(return)i(mr;)509 1540 y(/*)e(ignore)i(notificat)q(ion)h(messages)g(from)e(the)g(kernel)h(*/)509 1631 y(if)e(\(request-)q(>ms)q(g_)q(lo)q(cal)q(_p)q(ort)j(==)e(task_notif)q(y\()q (\)\))688 1677 y(continue;)509 1768 y(/*)f(demux)h(and)g(process)h(the)f(requ\ est,)i(generatin)q(g)f(a)e(reply)i(*/)509 1860 y(\(void\))g(\(*function)q(\)\ \()q(req)q(ue)q(st,)h(&reply->)q(Hea)q(d\))q(;)509 1951 y(/*)d(send)h(the)g (reply,)h(if)e(necessary)j(*/)509 2042 y(if)d(\(\(reply->)q(Hea)q(d.)q(ms)q (g_r)q(em)q(ote)q(_p)q(or)q(t)i(!=)f(PORT_NULL\))i(&&)598 2088 y(\(reply->)q (Ret)q(Co)q(de)g(!=)d(MIG_NO_R)q(EPL)q(Y\))q(\))i({)688 2134 y(/*)e(don't)i (block)f(if)f(the)h(reply)h(port)f(is)f(full)h(*/)688 2225 y(\(void\))h(msg_s\ end\()q(&re)q(pl)q(y-)q(>He)q(ad)q(,)g(SEND_TIM)q(EO)q(UT,)h(0\);)509 2271 y (})329 2316 y(})150 2362 y(})g eop %%Page: 11 8 bop 150 162 a fd(3.2)41 b(Server)12 b(main)e(pr)n(ogram)1158 b fe(11)329 353 y ff(kr)24 b(=)e(port_set)q(_a)q(dd\()q(ta)q(sk_)q(se)q(lf)q(\(\),)k(port_set) q(,)f(server_p)q(or)q(t\);)329 399 y(if)f(\(kr)f(!=)g(KERN_SUC)q(CE)q(SS\))j ({)509 444 y(mach_error)q(\(")q(por)q(t_)q(se)q(t_a)q(dd)q(",)g(kr\);)509 490 y(exit\(1\);)329 535 y(})329 627 y(kr)e(=)e(port_set)q(_a)q(dd\()q(ta)q(sk_)q (se)q(lf)q(\(\),)k(port_set)q(,)f(task_not)q(if)q(y\(\))q(\);)329 672 y(if)f (\(kr)f(!=)g(KERN_SUC)q(CE)q(SS\))j({)509 718 y(mach_error)q(\(")q(por)q(t_)q (se)q(t_a)q(dd)q(",)g(kr\);)509 764 y(exit\(1\);)329 809 y(})329 901 y(/*)e (check)g(service)h(port)f(into)h(the)e(name)h(service)i(so)d(clients)i(can)f (find)g(it)f(*/)329 992 y(kr)h(=)e(netname_)q(ch)q(eck)q(_i)q(n\(n)q(am)q(e_) q(ser)q(ve)q(r_p)q(or)q(t,)k("RandomSe)q(rv)q(erP)q(or)q(t",)822 1038 y(PORT_\ NUL)q(L,)g(server_po)q(rt)q(\);)329 1083 y(if)e(\(kr)f(!=)g(KERN_SUC)q(CE)q (SS\))j({)509 1129 y(mach_error)q(\(")q(net)q(na)q(me)q(_ch)q(ec)q(k_i)q(n")q (,)g(kr\);)509 1175 y(exit\(1\);)329 1220 y(})329 1312 y(/*)e(call)g(the)f (standard)j(service)f(loop;)g(should)g(never)f(return)h(*/)329 1403 y(kr)f (=)e(mig_serv)q(er)q(\(po)q(rt)q(_se)q(t,)k(random_se)q(rv)q(er)q(\);)329 1449 y(mach_err)q(or\()q("m)q(ig)q(_se)q(rv)q(er")q(,)g(kr\);)329 1494 y(exit\(2\)\ ;)150 1540 y(})212 1631 y fe(The)11 b(following)d(code)j(is)f(the)g(library)f (routine)g fc(mig)r 13 2 v 13 w(server)p fe(.)150 1719 y ff(#include)26 b()150 1764 y(#include)g()150 1810 y (#include)g()150 1901 y(msg_retur)q(n_)q(t)150 1947 y(mig_serve)q(r\()q(ser)q(vi)q(ce,)g(function)q(\))329 1993 y(port_nam)q (e_t)g(service;)273 b(/*)23 b(receive)i(right)g(or)e(port)h(set)g(*/)329 2038 y(boolean_)q(t)h(\(*functi)q(on)q(\)\(\))q(;)183 b(/*)23 b(server)i(demux)f (&)f(processin)q(g)j(*/)150 2084 y({)329 2130 y(/*)352 2175 y(*)135 b(Buffers) 25 b(should)g(be)e(aligned)i(on)f(4-byte)h(boundaries)q(,)352 2221 y(*)135 b (so)23 b(that)h(internal)i(fields)f(are)e(aligned)j(properly)352 2267 y(*)135 b(for)23 b(int)h(fetches)h(and)f(stores.)352 2312 y(*/)329 2358 y(int)g(reque\ stbu)q(f[)q(MSG)q(_S)q(IZE)q(_M)q(AX)q(/si)q(ze)q(of\()q(in)q(t\))q(];)329 2403 y(int)g(replybuf[)q(MS)q(G_S)q(IZ)q(E_M)q(AX)q(/s)q(ize)q(of)q(\(in)q (t\))q(];)g eop %%Page: 10 9 bop 150 162 a fe(10)757 b fd(3)41 b(MIG)10 b(-)g(THE)h(MACH)f(INTERF)-5 b (ACE)11 b(GENERA)n(T)o(OR)212 307 y fe(This)e(server)h(may)g(get)f(some)h fc (EMERGENCY_MSGs)e fe(from)i(the)f(kernel)g(on)g(its)f fc(notify_port\(\))h fe (which)150 357 y(it)g(wishes)h(to)g(ignore.)k(The)d(most)f(common)g(sort)f (of)h fc(EMERGENCY_MSG)f fe(is)h(the)f(noti\014cation)g(of)g(a)i(port)e(death\ .)150 407 y(In)i(the)h(case)h(of)f(a)g(server)g(these)g(ports)f(are)h(usually) f(client)g(reply)g(ports.)20 b(The)12 b(library)e(routine)h fc(mig)r 13 2 v 13 w(server)150 457 y fe(ignores)j(all)g(messages)j(on)d(the)h fc(notify_port\(\ \))p fe(.)28 b(A)15 b(more)g(complicated)g(server)g(might)f(need)h(to)f(take) 150 506 y(action)c(on)g(some)h(of)f(these)g(messages)j(and)d(would)f(not)g (be)i(able)g(to)e(use)150 556 y(t)h(mig)r 13 2 v 12 w(server.)212 607 y(Note) 20 b(that)e(the)i(function)e fc(mach_error_string)g fe(is)h(a)h(library)e(rou\ tine)g(that)h(returns)g(the)g(string)150 657 y(associated)11 b(with)f(a)h(Mac\ h)g(error)g(code.)17 b(This)11 b(function)e(is)h(de\014ned)h(in)f fc(mach_err\ or.h)g fe(and)h(is)f(included)g(in)150 707 y fc(libmach.a)p fe(.)212 758 y (The)h(following)d(code)j(shows)f(a)h(typical)e(main)h(loop)g(for)f(a)i(MIG)f (server)n(.)150 851 y ff(/********)q(**)q(***)q(**)q(***)q(**)q(**)q(***)q (**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(**)q(***)q(**)172 897 y(*)68 b (Main)24 b(program)h(for)f(random)h(server)172 942 y(********)q(**)q(***)q (**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(**)q(***)q(**)q(***)q(**)q(**)q (***)q(*/)150 1034 y(#include)h()150 1079 y(#include)g()150 1125 y(#include)g()150 1171 y(#include)g()150 1216 y(#include)g()150 1308 y (extern)f(boolean_t)h(random_se)q(rv)q(er\()q(\);)161 b(/*)23 b(from)h(random\ Ser)q(ve)q(r.c)i(*/)150 1353 y(extern)f(msg_retur)q(n_t)h(mig_serv)q(er\()q (\);)161 b(/*)23 b(from)h(mig_serve)q(r.)q(c)h(*/)150 1445 y(main\(\))150 1490 y({)329 1536 y(port_nam)q(e_t)h(server_p)q(ort)q(;)329 1582 y(port_nam)q(e_t) g(port_set)q(;)329 1627 y(kern_ret)q(urn)q(_t)g(kr;)329 1719 y(/*)e(allocate) h(a)e(service)i(port)g(for)e(receivin)q(g)i(request)h(messages)f(*/)329 1810 y (kr)f(=)e(port_all)q(oc)q(ate)q(\(t)q(ask)q(_s)q(el)q(f\(\))q(,)k(&server_po) q(rt)q(\);)329 1856 y(if)e(\(kr)f(!=)g(KERN_SUC)q(CE)q(SS\))j({)509 1901 y (mach_error)q(\(")q(por)q(t_)q(al)q(loc)q(at)q(e",)g(kr\);)509 1947 y(exit\(1\ \);)329 1993 y(})329 2084 y(/*)e(allocate)h(a)e(port)h(set)g(to)f(hold)h(the) g(service)h(port)f(and)g(notify)h(port)f(*/)329 2175 y(kr)g(=)e(port_set)q (_a)q(llo)q(ca)q(te\()q(ta)q(sk)q(_se)q(lf)q(\(\),)k(&port_se)q(t\);)329 2221 y(if)e(\(kr)f(!=)g(KERN_SUC)q(CE)q(SS\))j({)509 2267 y(mach_error)q(\(")q(por) q(t_)q(se)q(t_a)q(ll)q(oca)q(te)q(",)g(kr\);)509 2312 y(exit\(1\);)329 2358 y (})329 2449 y(/*)e(put)f(the)h(service)h(port)f(and)g(notify)h(port)f(into)g (the)g(port)g(set)f(*/)g eop %%Page: 9 10 bop 150 162 a fd(3.2)41 b(Server)12 b(main)e(pr)n(ogram)1179 b fe(9)150 307 y (dif)o(ferent)11 b(messages:)21 b(one)12 b(for)g(the)f(get)r 13 2 v 13 w(rand\ om)h(function)f(which)g(will)g(have)i(a)f(msg)r 13 2 v 13 w(id)g(of)g(500;)g (one)g(for)f(the)150 357 y(reply)i(to)h(get)r 13 2 v 12 w(random)g(which)g (will)e(have)j(a)f(msg)r 13 2 v 13 w(id)g(of)f(600;)i(one)f(for)f(the)h(funct\ ion)e(get)r 13 2 v 13 w(secret)j(which)e(will)150 407 y(have)e(a)g(msg)r 13 2 v 13 w(id)e(of)h(501;)f(and)i(one)f(for)g(its)f(reply)h(which)g(will)f(have)i (a)f(msg)r 13 2 v 13 w(id)g(of)g(601.)15 b(The)c(msg)r 13 2 v 13 w(id)f(is)g (used)g(by)150 457 y(the)g(server)h(to)f(identify)e(which)i(message)i(it)d (has)i(received.)212 503 y(The)e(\014le)g fc(mach/std)r 13 2 v 12 w(types.def\ s)e fe(de\014nes)i(some)g(frequently)e(used)h(types.)15 b(In)8 b(this)f(case) j(the)e(relevant)150 549 y(de\014ntions)h(are:)150 633 y ff(type)24 b(int)181 b(=)22 b(MSG_TYPE)q(_I)q(NTE)q(GE)q(R_)q(32;)150 678 y(type)i(port_t)115 b (=)22 b(MSG_TYPE)q(_P)q(ORT)q(;)150 724 y(type)i(boolean_t)49 b(=)22 b(MSG_TY\ PE)q(_I)q(NTE)q(GE)q(R_)q(32;)150 824 y fe(The)17 b(MIG)f(defs)g(\014le)g(is) g(processed)h(by)e fc(cpp)h fe(before)g(it)g(is)f(processed)i(by)f(MIG.)g(Thu\ s)g(cpp)g(strips)f(of)o(f)h(the)150 874 y(comments)11 b(and)f(handles)h(the)f fc(#include)f fe(directives.)212 925 y(The)j(syntax)e(of)g(the)h(type)f(decla\ ration)h(is)f(to)h(de\014ne)g(the)g(C)f(type)h(name)g(\014rst)g(and)g(then)f (say)h(that)g(it)e(is)i(equal)150 975 y(to)i(an)h(IPC)f(type)g(name.)27 b(The) 14 b(set)f(of)h(de\014ned)f(IPC)h(types)f(can)h(be)g(found)e(in)h(the)h(MIG)f (document)g(or)g(in)g(the)150 1025 y(\014le)f fc()p fe(.)19 b (For)11 b(string)f(and)i(unstructured)f(types)g(the)h(number)f(of)h fd(bits)e fe(in)h(the)h(type)f(must)150 1074 y(follow)e(the)h(name.)212 1121 y(The)h (import)f(statement)h(gives)f(the)g(name)i(of)e(a)h(header)h(\014le)e(to)g (be)h(included)f(in)g(the)g(generated)h(code.)17 b(This)150 1167 y(header)10 b (\014le)g(must)g(de\014ne)g(any)g(non-standard)e(C)i(types)f(used)h(by)g(the) f(interface.)16 b(In)10 b(this)e(case)k(it)d(consists)g(of)g(the)150 1213 y (following)f(de\014nition:)150 1296 y ff(typedef)25 b(char)92 b(string25[2)q (5])q(;)212 1396 y fe(The)9 b(routine)d(declarations)i(specify)g(the)g(name)g (of)g(the)g(routine)e(and)i(the)g(order)g(and)g(types)f(of)h(the)f(ar)o(gumen\ ts.)150 1446 y(The)15 b(\014rst)g(ar)o(gument)g(is)g(the)f(port)g(to)g(which) h(the)f(message)j(will)d(be)h(sent.)29 b(The)16 b(speci\014cation)e fc(in)p fe (,)j fc(out)d fe(or)150 1496 y fc(inout)c fe(may)g(precede)i(the)e(name)h(of) f(any)g(other)f(parameter)j(and)e(specify)g(in)f(what)h(direction)f(the)h(ar) o(gument)g(is)150 1546 y(to)g(be)g(passed.)17 b(Any)10 b(unspeci\014ed)g(para\ meter)n(,)i(except)f(the)f(\014rst)g(one,)h(is)f(assumed)h(to)f(be)g(an)h fc (in)f fe(parameter)n(.)212 1597 y(MIG)i(generates)h(three)f(C)f(\014les)i(fro\ m)e(the)h(de\014nition)e(\014le.)21 b(The)13 b(\014le)f fc(random.h)f fe(de\ \014nes)i(the)e(functions)150 1646 y(to)e(be)h(called)f(by)g(a)i(client)d(of) i(the)f(server)h(and)f(should)g(be)g fc(#included)g fe(into)f(code)i(that)f (calls)h(those)f(functions.)150 1696 y fc(randomUser.c)h fe(is)h(the)g(code)g (to)g(create)h(and)f(send)g(the)g(messages)i(to)d(the)h(client)f(and)i(then)e (wait)h(to)f(receive)150 1746 y(the)i(reply)f(message.)23 b(When)13 b(the)f (reply)f(message)j(is)e(received,)h(any)g fc(out)e fe(or)h fc(inout)g fe(para\ meters)h(are)g(taken)150 1796 y(out)c(of)h(the)g(message)i(and)e(returned)g (as)h(function)d(parameters)k(to)d(the)h(caller)n(.)16 b(This)10 b(\014le)h (should)e(be)h(linked)f(with)150 1846 y(the)j(user)g(of)f(the)h(server)n(.)21 b fc(randomServer.c)11 b fe(is)h(the)f(server)i(side)f(of)f(the)h(message)i (interface.)21 b(It)11 b(unpacks)150 1896 y(the)k(request)g(message,)j(calls) d(a)h(function)d(provided)h(by)g(the)h(server)h(implementor)e(to)g(execute)i (the)f(request)150 1945 y(and)f(then)f(creates)i(the)f(reply)f(message.)28 b (The)14 b(server)g(implementor)f(must)h(write)f(a)h(main)g(program)g(and)f (the)150 1995 y(functions)8 b(that)i(execute)g(the)g(requests.)16 b(There)10 b (is)g(a)g(library)f(routine,)g fc(mig)r 13 2 v 12 w(server)p fe(,)h(that)f (provides)g(a)h(simple)150 2045 y(version)15 b(of)f(a)i(send)g(and)f(receive) h(loop.)30 b(In)14 b(the)i(example,)h(the)e(user)h(writes)e(the)h(code)h(whic\ h)f(sets)g(up)g(the)150 2095 y(ports)10 b(and)h(then)f(calls)h fc(mig)r 13 2 v 12 w(server)g fe(to)f(do)g(the)h(rest.)17 b(If)10 b(a)i(server)f(needs)g(more) g(control)f(over)g(possible)g(error)150 2145 y(conditions,)f(it)g(can)i(provi\ de)e(its)h(own)g(receive)h(and)f(send)h(loop.)150 2270 y fb(3.2)50 b(Server) 13 b(main)f(pr)o(ogram)150 2350 y fe(In)d(this)f(example)h(the)g(server)h(wai\ ts)e(on)h(a)h(port)r 13 2 v 11 w(set)g(containing)d(the)i fc(ServerPort)f fe (and)h fc(notify_port\(\))p fe(.)150 2399 y(The)k(thread)f(reply)f(port)g(is) h(not)f(included)g(in)h(this)f(set.)21 b(When)13 b(ports)e(are)i(created)g (they)f(are)g(not)g(a)g(member)h(of)150 2449 y(any)d(port)g(set)g(by)g(defaul\ t.)15 b(Thus)c(they)e(must)i(be)f(added)h(explicitly)d(to)i fc(port)r 13 2 v 12 w(set)p fe(.)g eop %%Page: 8 11 bop 150 162 a fe(8)778 b fd(3)41 b(MIG)10 b(-)g(THE)h(MACH)f(INTERF)-5 b(ACE) 11 b(GENERA)n(T)o(OR)150 307 y fa(3)60 b(MIG)15 b(-)g(The)f(Mach)h(Interface) f(Generator)150 400 y fe(Much)8 b(multi-task)e(communication)h(takes)h(the)g (form)f(of)h(one)f(or)h(more)g(tasks)g(requesting)f(services)h(or)g(responses) 150 450 y(from)13 b(another)g(task.)24 b(This)13 b(in)g(fact)h(is)f(a)g(descr\ iption)f(of)h(a)h(Mach)g(server)f(process.)25 b(Since)14 b(the)f(creation)g (and)150 500 y(reading)k(of)f(messages)j(requires)e(a)h(lot)e(of)h(repetitiou\ s)e(code,)20 b(it)c(should)g(come)i(as)g(no)f(great)g(surpise)g(that)150 549 y (Mach)e(provides)f(a)g(compiler)h(to)e(produce)i(a)g(remote)f(procedure)h(cal\ l)f(interface)h(to)f(IPC)g(message)i(passing.)150 599 y(A)d(complete)h(descri\ ption)d(of)i(MIG)g(including)e(an)j(example)g(of)f(its)f(use)i(can)g(be)f(fou\ nd)f(in)h fd(MIG)f(-)h(the)g(Mach)150 649 y(Interface)d(Generator)h fe(by)e (Draves,)j(Jones)e(and)h(Thompson.)212 695 y(A)f(brief)f(example)i(of)e(the)g (use)h(of)g(MIG)f(follows.)15 b(The)10 b(problem)f(that)g(is)g(to)g(be)h(solv\ ed)g(is)f(to)g(write)g(a)h(simple)150 740 y(server)g(that)f(will)g(return)g (either)g(a)h(random)g(integer)f(or)g(a)i(random)e(string.)15 b(The)10 b(user) g(interface)g(to)f(this)g(server)h(is)150 786 y(to)g(consist)f(of)h(two)g(cal\ ls:)150 865 y ff(ret_code)26 b(=)d(get_random)q(\(s)q(erv)q(er)q(_po)q(rt)q (,n)q(um\))307 911 y(port_t)47 b(server_p)q(ort)q(;)307 956 y(int)113 b(num;) 150 1048 y(ret_code)26 b(=)d(get_secret)q(\(s)q(erv)q(er)q(_po)q(rt)q(,p)q (ass)q(wo)q(rd\))307 1093 y(port_t)47 b(server_p)q(ort)q(;)307 1139 y(string2\ 5)26 b(password;)150 1304 y fb(3.1)50 b(MIG)13 b(De\014nition)e(\014le)150 1382 y fe(The)18 b(subsystem)f(implementor)g(must)g(\014rst)g(write)g(a)h(MIG) f(de\014nition)f(\014le)h(to)g(specify)g(the)g(details)g(of)g(the)150 1432 y (procdure)11 b(ar)o(guments)g(and)h(the)f(messages)i(to)d(be)i(used.)19 b(MIG) 11 b(understands)f(dif)o(ferent)h(kinds)f(of)h(routines)f(and)150 1481 y(many) 15 b(obscure)h(options)d(in)h(the)h(way)g(messages)i(are)f(to)e(be)i(formatte\ d,)g(sent)f(and)g(received.)30 b(But)15 b(for)f(this)150 1531 y(simple)d(case) j(it)d(is)g(enough)g(to)g(de\014ne)h(the)g(name)g(of)g(the)f(server)n(,)j(the) d(types)g(of)h(the)f(ar)o(guments)h(that)f(are)i(being)150 1581 y(used,)e(and) f(the)g(routines)f(that)h(are)h(desired.)16 b(The)11 b(following)d(MIG)i(de\ \014nition)e(\014le)j(will)e(suf)o(\014ce)i(to)f(do)g(this:)150 1668 y ff(sub\ system)26 b(random)f(500;)150 1760 y(#include)h()150 1851 y(type)e(string25)71 b(=)22 b(\(MSG_TYP)q(E_)q(STR)q(IN)q (G_)q(C,8)q(*2)q(5\);)150 1942 y(import)j("random_t)q(ype)q(s.)q(h")q(;)150 2034 y(routine)g(get_rand)q(om\()509 2079 y(requestpor)q(t)115 b(server_p)q (ort)h(:)23 b(port_t;)509 2125 y(out)292 b(num)h(:)23 b(int\);)150 2216 y(rou\ tine)i(get_secr)q(et\()509 2262 y(requestpor)q(t)115 b(server_p)q(ort)h(:)23 b (port_t;)509 2308 y(out)292 b(password)183 b(:)23 b(string25\))q(;)212 2399 y fe(The)15 b(\014rst)f(line)f(of)g(the)h(de\014nition)e(\014le)j(states)f(that) f(the)h(name)h(of)f(the)f(subsytem)h(is)g(to)f(be)i fc(random)e fe(and)150 2449 y(the)g(messages)i(that)e(are)h(created)h(will)d(start)h(with)f(the)h (message)i(id)e(of)g(500.)24 b(This)14 b(interface)f(will)f(send)i(four)g eop %%Page: 7 12 bop 150 162 a fd(2.12)41 b(Example)11 b(V)-5 b(,)11 b(masterslave.c)1092 b fe (7)240 307 y ff(while)24 b(\(count)h(!=)e(0\))329 353 y(conditio)q(n_w)q(ai)q (t\()q(don)q(e,)j(lock\);)240 399 y(mutex_unlo)q(ck)q(\(lo)q(ck)q(\);)240 444 y(printf\("Al)q(l)g(%d)d(slaves)i(have)f(finished.)q(\\n")q(,)i(nslaves\);) 240 490 y(cthread_ex)q(it)q(\(0\))q(;)150 535 y(})150 627 y(main\(\))150 672 y ({)240 718 y(init\(\);)240 764 y(master\(\(in)q(t\))g(random\(\))g(%)d(16\);) 46 b(/*)23 b(create)i(up)f(to)f(15)g(slaves)i(*/)150 809 y(})g eop %%Page: 6 13 bop 150 162 a fe(6)363 b fd(2)41 b(C)10 b(THREADS:)h(MASTER)g(THREAD)g(SP)-5 b(A)n(WNING)10 b(CONCURRENT)g(SLA)n(VES)150 307 y ff({)240 353 y(cthread_in)q (it)q(\(\);)240 399 y(count)24 b(=)f(0;)240 444 y(lock)h(=)f(mutex_allo)q(c\() q(\);)240 490 y(done)h(=)f(condition_)q(al)q(loc)q(\(\))q(;)240 535 y(srandom\ \(ti)q(me)q(\(\(i)q(nt)j(*\))d(0\)\);)47 b(/*)23 b(initializ)q(e)j(random)f (number)g(generator)h(*/)150 581 y(})150 672 y(/*)172 718 y(*)d(Each)h(slave) h(just)f(counts)h(up)e(to)g(its)h(argument,)i(yielding)g(the)e(processor)i (on)172 764 y(*)d(each)h(iteratio)q(n.)48 b(When)24 b(it)g(is)f(finished,)j (it)d(decremen)q(ts)j(the)e(global)g(count)172 809 y(*)f(and)h(signals)h(that) f(it)g(is)f(done.)172 855 y(*/)150 901 y(slave\(n\))240 946 y(int)g(n;)150 992 y({)240 1038 y(int)g(i;)240 1129 y(for)g(\(i)h(=)e(0;)i(i)e(<)h(n;)h(i)e(+=)i (1\))329 1175 y(cthread_)q(yie)q(ld)q(\(\))q(;)240 1220 y(mutex_lock)q(\(l)q (ock)q(\);)240 1266 y(count)g(-=)f(1;)240 1312 y(printf\("Sl)q(av)q(e)i(finis\ hed)h(%d)d(cycles.\\)q(n")q(,)i(n\);)240 1357 y(condition_)q(si)q(gna)q(l\()q (do)q(ne\))q(;)240 1403 y(mutex_unlo)q(ck)q(\(lo)q(ck)q(\);)150 1449 y(})150 1540 y(/*)172 1586 y(*)e(The)h(master)h(spawns)g(a)e(given)h(number)h(of)e (slaves)i(and)f(then)g(waits)g(for)g(them)g(all)g(to)172 1631 y(*)f(finish.) 172 1677 y(*/)150 1723 y(master\(ns)q(la)q(ves)q(\))240 1768 y(int)g(nslaves;) 150 1814 y({)240 1860 y(int)g(i;)240 1951 y(for)g(\(i)h(=)e(1;)i(i)e(<=)i(nsl\ aves;)h(i)e(+=)h(1\))f({)329 1997 y(mutex_lo)q(ck\()q(lo)q(ck)q(\);)329 2042 y (/*)352 2088 y(*)g(Fork)h(a)e(slave)j(and)f(detach)h(it,)352 2134 y(*)e(since) h(the)g(master)h(never)f(joins)h(it)e(individua)q(lly)q(.)352 2179 y(*/)329 2225 y(count)i(+=)e(1;)329 2271 y(cthread_)q(det)q(ac)q(h\()q(cth)q(re)q(ad_) q(fo)q(rk)q(\(sl)q(av)q(e,)j(random\(\))g(%)c(1000\)\);)329 2316 y(mutex_un)q (loc)q(k\()q(lo)q(ck\))q(;)240 2362 y(})240 2408 y(mutex_lock)q(\(l)q(ock)q (\);)g eop %%Page: 5 14 bop 150 162 a fd(2.10)41 b(Y)m(ielding)9 b(the)h(Pr)n(ocessor)i(to)e(other)g (Thr)n(eads)856 b fe(5)150 307 y fb(2.10)50 b(Y)n(ielding)12 b(the)f(Pr)o(oce\ ssor)j(to)e(other)g(Thr)o(eads)150 385 y fe(This)c(procedure)g(is)h(a)f(hint) f(to)h(the)g(scheduler)n(,)i(suggesting)c(that)i(this)f(would)h(be)g(a)h(conv\ enient)e(point)g(to)h(schedule)150 435 y(another)k(thread)h(to)f(run)g(on)h (the)f(current)h(processor)n(.)23 b(Calls)12 b(to)h fc(cthread_yield)e fe(are) j(unnecessary)g(in)e(an)150 485 y(implementation)d(with)h(preemptive)h(schedu\ ling,)f(but)g(may)h(be)g(required)f(to)g(avoid)g(starvation)g(in)g(a)h(corout\ ine)150 534 y(based)g(implementation.)240 622 y ff(int)23 b(i,)h(n;)240 713 y (/*)f(n)g(is)g(set)h(previously)i(*/)240 805 y(for)d(\(i)h(=)e(0;)i(i)e(<)h (n;)h(i)e(+=)i(1\))307 850 y(cthread_y)q(iel)q(d\()q(\);)150 1024 y fb(2.11) 50 b(Exiting)11 b(a)i(C)f(Thr)o(ead)150 1102 y fc(cthread_exit)h fe(causes)i (termination)d(of)i(the)g(calling)f(thread.)26 b(An)14 b(implicit)e fc(cthrea\ d_exit)h fe(occurs)150 1151 y(when)g(the)g(top)f(level)g(function)g(of)g(a)i (thread)e(returns.)23 b(The)14 b(result)e(parameter)i(will)d(be)j(passed)f (to)g(the)f(thread)150 1201 y(that)e(joins)f(the)h(caller)n(,)h(or)f(discarde\ d)h(if)e(the)h(caller)h(is)f(detached.)240 1289 y ff(cthread_ex)q(it)q(\(0\)) q(;)150 1462 y fb(2.12)50 b(Example)13 b(V)-6 b(,)12 b(masterslave.c)150 1536 y ff(/*)172 1582 y(*)23 b(This)h(program)i(is)d(an)g(example)i(of)f(a)f(maste\ r)h(thread)h(spawning)h(a)d(number)i(of)172 1627 y(*)e(concurre)q(nt)j(slaves\ .)48 b(The)23 b(master)i(thread)g(waits)g(until)f(all)g(of)f(the)h(slaves)h (have)172 1673 y(*)e(finished)j(to)d(exit.)47 b(Once)24 b(created)i(a)c(slave) j(process)g(doesn't)h(do)d(much)h(in)f(this)172 1719 y(*)g(simple)i(example)g (except)g(loop.)47 b(A)23 b(count)i(variable)g(is)f(used)g(by)f(the)h(master) h(and)172 1764 y(*)e(slave)i(processes)h(to)d(keep)h(track)h(of)e(the)h(curre\ nt)h(number)g(of)e(slaves)i(executing)q(.)172 1810 y(*)e(A)g(mutex)i(is)e(ass\ ociate)q(d)i(with)f(this)h(count)f(variable,)i(and)e(a)f(condition)j(variable) 172 1856 y(*)d(with)h(the)g(mutex.)47 b(This)24 b(program)i(is)d(a)g(simple)i (demonstrat)q(io)q(n)h(of)d(the)g(use)h(of)172 1901 y(*)f(mutex)i(and)e(condi\ tio)q(n)j(variables.)172 1947 y(*/)150 2038 y(#include)g()150 2084 y (#include)g()150 2175 y(int)e(count;)204 b(/*)23 b(number)i (of)e(slaves)i(active)g(*/)150 2221 y(mutex_t)g(lock;)137 b(/*)23 b(mutual)i (exclusion)h(for)e(count)g(*/)150 2267 y(condition)q(_t)i(done;)47 b(/*)23 b (signalled)j(each)e(time)g(a)f(slave)i(finishes)h(*/)150 2358 y(extern)f(long) f(random\(\);)150 2449 y(init\(\))g eop %%Page: 4 15 bop 150 162 a fe(4)363 b fd(2)41 b(C)10 b(THREADS:)h(MASTER)g(THREAD)g(SP)-5 b(A)n(WNING)10 b(CONCURRENT)g(SLA)n(VES)240 307 y ff(mutex_t)25 b(lock;)240 353 y(condition_)q(t)h(done;)240 444 y(mutex_lock)q(\(l)q(ock)q(\);)240 490 y (...)240 535 y(while)e(\(count)h(!=)e(0\))307 581 y(condition)q(_wa)q(it)q (\(d)q(one)q(,)j(lock\);)240 627 y(...)240 672 y(mutex_unlo)q(ck)q(\(lo)q(ck) q(\);)150 817 y fb(2.7)50 b(Signalling)11 b(a)h(Condition)150 895 y fc(condit\ ion_signal)e fe(is)g(called)i(when)f(one)g(thread)g(wishes)g(to)f(indicate)h (that)f(the)h(condition)e(represented)150 945 y(by)i(the)h(condition)e(variab\ le)i(may)g(now)f(be)h(true.)21 b(If)11 b(any)h(threads)g(are)h(waiting)d(via) i fc(condition_wait)p fe(,)f(at)150 995 y(least)f(one)h(of)f(them)g(will)f (be)i(awakened.)17 b(If)10 b(no)f(threads)i(are)g(waiting,)e(nothing)f(happen\ s.)240 1062 y ff(condition_)q(t)26 b(done;)47 b(/*)23 b(signalled)j(each)e (time)g(a)f(slave)h(finishes)i(*/)240 1107 y(condition_)q(si)q(gna)q(l\()q (do)q(ne\))q(;)150 1252 y fb(2.8)50 b(Forking)12 b(a)g(C)h(Thr)o(ead)150 1330 y fe(This)g(function)f(takes)h(two)g(parameters:)22 b(a)14 b(function)d(for)i (the)g(new)h(thread)f(to)f(execute,)j(and)f(a)f(parameter)i(to)150 1380 y(thi\ s)f(function.)29 b fc(cthread_fork)14 b fe(creates)j(a)e(new)h(thread)f(of)g (control)f(in)g(which)h(the)g(speci\014ed)h(function)150 1429 y(is)d(executed) h(concurrently)e(with)g(the)h(caller)r(')n(s)g(thread.)25 b(This)13 b(is)g (the)g(sole)h(means)g(of)f(creating)g(new)h(threads.)150 1479 y(A)21 b(parame\ ter)h(that)e(is)h(lar)o(ger)g(than)f(a)i(pointer)d(must)i(be)g(passed)h(by)f (reference.)49 b(Similarly)m(,)23 b(multiple)150 1529 y(parameters)15 b(must) f(be)h(simulated)e(by)h(passing)g(a)g(pointer)f(to)h(a)g(structure)g(containi\ ng)e(several)j(components.)150 1579 y(The)e(call)f(to)g fc(cthread_fork)f fe (returns)g(a)i(thread)f(identi\014er)f(that)h(can)g(be)h(passed)g(to)e fc(cth\ read_join)g fe(or)150 1629 y fc(cthread_detach)p fe(.)k(Every)10 b(thread)g (must)g(be)h(either)f(joined)f(or)h(detached)h(exactly)f(once.)240 1696 y ff (/*)45 b(slave)25 b(is)e(a)g(function)j(that)e(expects)h(an)e(integer)j(param\ eter)48 b(*/)240 1741 y(/*)d(see)24 b(Detaching)i(a)d(C)g(Thread)i(for)e(desc\ ript)q(io)q(n)i(of)f(chtread_de)q(ta)q(ch)48 b(*/)240 1833 y(cthread_de)q(ta) q(ch\()q(ct)q(hr)q(ead)q(_f)q(ork)q(\(s)q(la)q(ve,)26 b(random\(\))g(%)d(1000\ \)\);)150 1977 y fb(2.9)50 b(Detaching)11 b(a)i(C)f(Thr)o(ead)150 2055 y fc (cthread_detach)c fe(is)g(used)h(to)f(indicate)g(that)g(a)i(thread)e(will)g (never)h(be)g(joined.)14 b(A)9 b(thread)f(may)h(be)g(detached)150 2105 y(at)i (any)h(time)f(after)g(it)g(is)g(forked,)g(as)h(long)e(as)i(no)f(other)f(attem\ pt)h(at)h(joining)d(or)i(detaching)f(has)i(been)g(made.)19 b(In)150 2155 y (the)13 b(example)g(below)m(,)h(at)e(the)h(time)g(the)f(thread)h(was)g(forked\ ,)g(it)f(was)i(known)e(that)g(it)g(would)f(never)i(be)g(joined)150 2204 y(and) d(therefore)h(it)e(was)i(detached.)240 2272 y ff(/*)45 b(slave)25 b(is)e(a)g (function)j(that)e(expects)h(an)e(integer)j(parameter)48 b(*/)240 2317 y(/*)d (see)24 b(Forking)h(a)e(C)g(Thread)i(for)f(descriptio)q(n)i(of)d(chtread_f)q (ork)49 b(*/)240 2409 y(cthread_de)q(ta)q(ch\()q(ct)q(hr)q(ead)q(_f)q(ork)q (\(s)q(la)q(ve,)26 b(random\(\))g(%)d(1000\)\);)g eop %%Page: 3 16 bop 150 162 a fd(2.2)41 b(Allocation)9 b(of)g(a)i(Mutex)f(V)-5 b(ariable) 1023 b fe(3)240 307 y ff(cthread_in)q(it)q(\(\);)150 487 y fb(2.2)50 b(Alloca\ tion)11 b(of)h(a)g(Mutex)g(V)-5 b(ariable)150 566 y fc(mutex_alloc)9 b fe(pro\ vides)h(dynamic)g(allocation)f(of)h(a)h(mutex)f(variable.)240 657 y ff(mutex_\ t)25 b(lock;)137 b(/*)23 b(mutual)i(exclusion)h(for)e(count)g(*/)240 703 y (lock)g(=)f(mutex_allo)q(c\()q(\);)150 883 y fb(2.3)50 b(Locking)12 b(a)g(Mut\ ex)g(V)-5 b(ariable)150 962 y fc(mutex_lock)12 b fe(attempts)g(to)h(lock)f (the)h(given)f(mutex)g(variable.)23 b(If)13 b(the)f(mutex)h(is)g(already)g (locked)f(this)g(call)150 1012 y(blocks)e(until)f(the)i(mutex)g(is)f(unlocked\ .)17 b(If)11 b(several)g(threads)g(attempt)f(to)h(lock)f(the)h(same)h(mutex)f (concurrently)m(,)150 1062 y(one)f(will)f(succeed,)j(and)e(the)f(others)h(wil\ l)f(block)g(until)f(the)i(mutex)g(is)f(unlocked.)15 b(A)10 b(deadlock)g(will) f(result)g(from)150 1112 y(a)i(thread)f(attempting)f(to)h(lock)f(a)i(mutex)f (it)g(has)h(already)f(locked.)240 1203 y ff(mutex_t)25 b(lock;)137 b(/*)23 b (mutual)i(exclusion)h(for)e(count)g(*/)240 1249 y(mutex_lock)q(\(l)q(ock)q (\);)150 1429 y fb(2.4)50 b(Unlocking)11 b(a)i(Mutex)e(V)-5 b(ariable)150 1508 y fc(mutex_unlock)9 b fe(unlocks)h(the)g(mutex)g(giving)f(other)g(threads)h (a)h(chance)h(to)e(lock)f(it.)240 1599 y ff(mutex_t)25 b(lock;)137 b(/*)23 b (mutual)i(exclusion)h(for)e(count)g(*/)240 1645 y(mutex_unlo)q(ck)q(\(lo)q (ck)q(\);)150 1825 y fb(2.5)50 b(Allocation)11 b(of)h(a)g(Condition)f(V)-5 b (ariable)150 1904 y fc(condition_alloc)9 b fe(provides)g(dynamic)i(allocation) e(of)h(a)h(condition)d(variable.)240 1995 y ff(condition_)q(t)26 b(done;)47 b (/*)23 b(signalled)j(each)e(time)g(a)f(slave)h(finishes)i(*/)240 2041 y(done) e(=)f(condition_)q(al)q(loc)q(\(\))q(;)150 2221 y fb(2.6)50 b(W)m(aiting)11 b (on)h(a)h(Condition)150 2300 y fe(This)e(function)e(unlocks)h(the)h(mutex)f (it)g(takes)h(as)h(a)f(parameter)n(,)i(suspending)c(the)i(calling)f(thread)h (until)e(another)150 2350 y(thread)i(calls)h fc(condition_signal)d fe(on)i (the)g(same)i(condition)c(variable.)19 b(The)12 b(mutex)f(is)g(then)g(locked) g(and)150 2399 y(the)g(thread)h(resumes.)20 b(There)13 b(is)e(no)g(guarantee) h(that)f(the)g(condition)e(will)i(be)g(true)g(when)h(the)f(thread)h(resumes,) 150 2449 y(therefore)e fc(condition_wait)f fe(should)g(always)i(be)g(used)f (in)g(the)g(form)g(below)m(.)g eop %%Page: 2 17 bop 150 162 a fe(2)363 b fd(2)41 b(C)10 b(THREADS:)h(MASTER)g(THREAD)g(SP)-5 b(A)n(WNING)10 b(CONCURRENT)g(SLA)n(VES)150 307 y fe(time)h(the)f(master)i (thread)f(is)g(signalled)e(by)i(a)g fc(condition_signal)f fe(call,)h(it)f(tes\ ts)h(the)g fc(count)f fe(for)h(a)g(value)150 357 y(of)f(zero.)212 407 y fc (cthread_init)i fe(is)g(the)g(\014rst)g(function)f(called)i(in)f(the)g(exampl\ e)h(program.)22 b(This)13 b(function)e(initializes)150 457 y(the)j(C)g(thread\ s)g(implementation)f(and)i(must)f(be)g(called)h(before)f(any)g(of)g(the)g(oth\ er)g(cthread)g(functions.)27 b(If)14 b(a)150 507 y(program)c(is)h(loaded)f (with)g(the)g(Mach)i(version)d(of)i fc(crt0)p fe(,)g(this)e(call)i(is)f(no)h (longer)f(necessary)i(as)f(it)f(has)h(already)150 557 y(been)f(done)g(by)g fc (crt0)f fe(\(or)h fc(gcrt0)f fe(or)h fc(moncrt0)p fe(\).)15 b(The)10 b fc(cou\ nt)g fe(which)f(represents)h(the)g(current)g(number)f(of)150 606 y(slaves)k (is)f(set)g(to)g(zero.)22 b fc(mutex_alloc)11 b fe(is)i(called)f(to)g(allocat\ e)g(a)h(mutex)f(assigned)g(to)g(the)g(variable)g fc(lock)p fe(.)150 656 y fc (condition_alloc)c fe(is)i(used)g(to)f(allocate)h(a)g(condition)e(object)h (assigned)h(to)f(the)g(variable)h fc(done)p fe(.)15 b(The)10 b(last)150 706 y (initialization)d(call)k(is)f(to)f(the)h(random)h(number)f(generator)n(.)212 756 y(After)18 b(initialization)o(,)f(the)h(master)g(thread)g(loops)e(creatin\ g)i(the)f(number)h(of)f(slave)h(processes)h(desired)150 806 y(and)e(increment\ ing)g fc(count)g fe(with)f(each)i(creation.)37 b fc(mutex_lock)16 b fe(is)h (called)h(at)f(the)g(beginning)e(of)i(the)150 856 y(loop.)29 b(This)15 b(call) g(results)f(in)h(either)f(locking)g(the)h(variable)g fc(lock)p fe(,)h(or)f (blocking)e(until)g fc(lock)i fe(is)g(unlocked)150 905 y(by)f(some)i(other)e (thread.)29 b(The)16 b(return)e(of)g fc(mutex_lock)g fe(signals)h(that)f(the) g(master)i(can)f(now)g(change)g(the)150 955 y(variable)8 b fc(count)h fe(know\ ing)e(that)h(no)g(other)g(thread)g(will)g(be)g(accessing)i(this)e(variable)g (until)f(the)h(master)i(unlocks)150 1005 y(the)16 b(mutex.)34 b fc(count)16 b fe(is)h(incremented,)h(and)f(a)f(slave)h(is)f(created.)36 b(T)m(o)16 b(create) i(a)f(slave,)i(the)d(master)h(calls)150 1055 y fc(cthread_fork)e fe(followed) g(by)h fc(cthread_detach)p fe(.)32 b fc(cthread_fork)15 b fe(creates)i(a)g (new)f(thread)g(of)150 1105 y(control)f(which)h(executes)h(concurrently)e(wit\ h)g(the)h(master)n(.)35 b fc(cthread_fork)15 b fe(takes)i(as)f(a)h(parameter) h(a)150 1155 y(function)10 b(which)h(the)g(new)h(thread)g(is)f(to)g(execute.) 20 b(Since)12 b(the)g(master)g(does)g(not)e(intend)h(to)g(later)g(rendez-vous) 150 1204 y(with)i(the)h(slave,)i fc(cthread_detach)d fe(is)h(called.)28 b(Onc\ e)14 b(the)g(master)h(has)g(incremented)f(the)g fc(count)g fe(and)150 1254 y (created)d(a)g(slave,)h fc(mutex_unlock)d fe(is)h(called)h(to)f(give)g(the)g (other)g(threads)g(a)h(chance)h(to)e(lock)g(the)g(mutex)g(and)150 1304 y(cons\ equently)f(access)k(the)d fc(count)g fe(variable.)212 1354 y(Having)16 b(crea\ ted)h(the)f(desired)g(number)g(of)g(slaves,)i(the)e(master)h(thread)f(stops)g (looping)e(and)i(waits)g(for)150 1404 y(all)h(of)h(the)f(slave)h(threads)g (to)f(\014nish)g(execution.)37 b(The)19 b(variable)e fc(count)g fe(signals)g (the)h(number)f(of)h(slave)150 1454 y(processes)f(still)e(executing.)34 b fc (mutex_lock)15 b fe(is)h(called)h(so)f(the)g(master)h(may)g(safely)g(access)h (the)e fc(count)150 1503 y fe(variable.)h(Now)10 b(the)h(master)g(thread)g (must)f(wait)g(on)h(the)f(condition)f fc(done)h fe(by)g(calling)g fc(conditio\ n_wait)p fe(.)150 1553 y fc(condition_wait)i fe(unlocks)g(the)h(mutex)g(and)g (suspends)g(the)g(master)n(,)i(letting)c(other)i(threads)g(change)g(the)150 1603 y fc(count)8 b fe(variable.)15 b(When)8 b fc(condition_wait)f fe(returns\ ,)h(the)g(mutex)g(is)g(automatically)f(locked.)15 b(The)8 b(master)150 1653 y (resumes)i(and)e(checks)i(the)e fc(count)g fe(to)g(see)i(if)e(it)f(is)i(in)f (fact)g(equal)h(to)f(zero.)16 b(Since)8 b(there)h(is)f(no)g(gaurantee)h(that) f(the)150 1703 y(condition)e(will)h(be)h(true)g(when)g(the)g(master)h(is)e (resumed,)j(the)e fc(condition_wait)f fe(is)h(called)g(in)f(a)i(loop)e(ending) 150 1753 y(when)13 b(the)f fc(count)h fe(is)f(zero.)24 b(Before)13 b(exiting) e(the)h(master)i(calls)f fc(mutex_unlock)p fe(.)22 b fc(cthread_exit)11 b fe (is)150 1802 y(called)g(to)e(terminate)h(the)g(master)h(thread.)212 1852 y (When)i(the)f(new)g(slave)g(was)h(created)g(via)f fc(cthread_fork)p fe(,)g (it)f(was)i(given)e(a)i(function)e(to)g(execute)i(and)150 1902 y(one)d(parame\ ter)g(to)f(pass)h(to)f(that)g(function.)14 b(In)9 b(our)g(example,)i(the)f (slave)f(function)f(is)i(given)f(a)h(random)f(number)150 1952 y(as)j(a)g(para\ meter)n(.)19 b(The)12 b(slave)g(loops)e(this)h(number)g(of)g(times)g(calling) f(a)i(function)e fc(cthread_yield)p fe(,)h(which)150 2002 y(yields)e(the)g (processor)h(to)f(other)g(threads.)16 b(When)10 b(\014nished)f(looping,)f(the) h(thread)h(must)f(decrement)i(the)e fc(count)150 2052 y fe(variable)j(because) i(it)d(is)h(about)f(to)h(exit.)21 b(In)12 b(order)f(to)h(safely)g(access)j (the)d fc(count)p fe(,)g fc(mutex_lock)g fe(is)f(called.)150 2102 y(Once)f (the)f(mutex)g fc(lock)g fe(is)g(locked,)h(the)f fc(count)g fe(is)g(decrement\ ed.)17 b(Next)9 b fc(condition_signal)f fe(is)h(called)150 2151 y(to)j(indica\ te)h(that)f(the)h(condition)e(represented)j(by)e(the)h(condition)e(variable)i fc(done)f fe(may)i(be)f(true.)24 b(The)14 b(slave)150 2201 y(calls)c fc(mutex\ _unlock)g fe(and)g(exits.)150 2321 y fb(2.1)50 b(Initializing)11 b(the)h(C)g (Thr)o(eads)h(Package)150 2399 y fe(This)g(initialization)e(function)h(must)h (be)h(called)f(before)h(any)f(other)g(C)g(Thread)i(functions.)23 b(This)14 b (call)f(is)h(now)150 2449 y(called)d(automatically)e(by)h fc(crt0)p fe(,)g (but)g(multiple)e(calls)j(to)e(this)h(routine)f(are)i(harmless.)g eop eos end TeXDict begin 300 @start bos /fa [ 0 0 0 0 0 0 0 0 0 0 0 0 33 33 0 0 17 0 20 20 20 20 20 20 20 33 43 43 30 60 60 47 15 20 30 30 30 60 50 20 20 20 30 34 15 20 15 17 30 30 30 30 30 30 30 30 30 30 20 20 20 34 30 30 56 43 40 43 43 40 37 47 47 23 30 47 40 56 43 47 37 47 43 33 40 43 43 60 43 43 40 20 30 20 20 20 20 30 33 27 33 27 20 30 33 17 20 33 17 50 33 30 33 33 27 23 20 33 30 43 30 30 27 30 60 20 20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 30 30 10 30 30 30 30 17 30 30 20 20 33 33 0 30 30 30 15 0 32 21 20 30 30 30 60 60 0 30 0 20 20 20 20 20 20 20 20 0 20 20 0 20 20 20 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60 0 18 0 0 0 0 40 47 60 20 0 0 0 0 0 43 0 0 0 17 0 0 17 30 43 33 0 0 0 0 ] /Times-Bold 1000 655360 943718 pf /fb [ 0 0 0 0 0 0 0 0 0 0 0 0 28 28 0 0 14 0 17 17 17 17 17 17 17 28 36 36 25 50 50 39 12 17 25 25 25 50 41 17 17 17 25 28 12 17 12 14 25 25 25 25 25 25 25 25 25 25 17 17 17 28 25 25 46 36 33 36 36 33 30 39 39 19 25 39 33 47 36 39 30 39 36 28 33 36 36 50 36 36 33 17 25 17 17 17 17 25 28 22 28 22 17 25 28 14 17 28 14 41 28 25 28 28 22 19 17 28 25 36 25 25 22 25 50 17 17 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 25 25 8 25 25 25 25 14 25 25 17 17 28 28 0 25 25 25 12 0 27 17 17 25 25 25 50 50 0 25 0 17 17 17 17 17 17 17 17 0 17 17 0 17 17 17 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50 0 15 0 0 0 0 33 39 50 16 0 0 0 0 0 36 0 0 0 14 0 0 14 25 36 28 0 0 0 0 ] /Times-Bold 1000 655360 786432 pf /fc [ 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 25 0 0 25 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 25 25 25 25 25 25 25 25 25 25 25 25 0 0 0 25 25 25 25 0 25 25 25 25 25 25 25 0 0 25 0 25 25 25 25 25 25 25 25 0 25 25 0 25 25 25 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 25 25 0 25 0 0 0 0 0 0 0 0 0 25 0 0 25 25 0 25 0 0 0 0 ] /Courier 1000 655360 655360 pf /fd [ 0 0 0 0 0 0 0 0 0 0 0 0 23 23 0 0 12 0 14 14 14 14 14 14 14 23 30 30 21 42 42 32 10 14 21 21 21 42 35 14 14 14 21 24 10 14 10 12 21 21 21 21 21 21 21 21 21 21 14 14 14 24 21 21 39 30 28 30 30 28 25 32 32 16 21 32 28 39 30 32 25 32 30 23 28 30 30 42 30 30 28 14 21 14 14 14 14 21 23 18 23 18 14 21 23 12 14 23 12 35 23 21 23 23 18 16 14 23 21 30 21 21 18 21 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 21 21 7 21 21 21 21 12 21 21 14 14 23 23 0 21 21 21 10 0 22 15 14 21 21 21 42 42 0 21 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 42 0 12 0 0 0 0 28 32 42 14 0 0 0 0 0 30 0 0 0 12 0 0 12 21 30 23 0 0 0 0 ] /Times-Bold 1000 655360 655360 pf /fe [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 12 0 14 14 14 14 14 14 14 21 28 28 21 37 39 30 10 14 23 21 21 35 32 14 14 14 21 28 10 14 10 12 21 21 21 21 21 21 21 21 21 21 14 14 16 28 21 21 38 25 25 28 30 25 25 30 30 14 18 28 23 35 28 30 25 30 25 21 23 30 25 35 25 23 23 16 23 16 14 14 14 21 21 18 21 18 12 21 21 12 12 18 12 30 21 21 21 21 16 16 12 21 18 28 18 18 16 21 37 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 21 21 7 21 21 21 21 9 23 21 14 14 21 21 0 21 21 21 10 0 22 15 14 23 23 21 37 42 0 21 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 23 30 39 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 28 21 0 0 0 0 ] /Times-Italic 1000 655360 655360 pf /ff df[<60F0F060>4 4 -4 0 12]58 dc dfe /fg [ 0 0 0 0 0 0 0 0 0 0 0 0 23 23 0 0 12 0 14 14 14 14 14 14 14 21 28 30 21 37 37 30 10 14 18 21 21 35 32 14 14 14 21 23 10 14 10 12 21 21 21 21 21 21 21 21 21 21 12 12 14 23 18 18 38 30 28 28 30 25 23 30 30 14 16 30 25 37 30 30 23 30 28 23 25 30 30 39 30 30 25 14 18 14 14 14 14 18 21 18 21 18 14 21 21 12 12 21 12 32 21 21 21 21 14 16 12 21 21 30 21 21 18 21 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 21 21 7 21 21 21 21 7 18 21 14 14 23 23 0 21 21 21 10 0 19 15 14 18 18 21 42 42 0 18 0 14 14 14 14 14 14 14 14 0 14 14 0 14 14 14 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 25 30 37 13 0 0 0 0 0 28 0 0 0 12 0 0 12 21 30 21 0 0 0 0 ] /Times-Roman 1000 655360 655360 pf /fh [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 10 0 12 12 12 12 12 12 12 21 27 27 19 37 37 29 9 12 19 19 19 37 31 12 12 12 19 21 9 12 9 10 19 19 19 19 19 19 19 19 19 19 12 12 12 21 19 19 35 27 25 27 27 25 23 29 29 15 19 29 25 35 27 29 23 29 27 21 25 27 27 37 27 27 25 12 19 12 12 12 12 19 21 17 21 17 12 19 21 10 12 21 10 31 21 19 21 21 17 15 12 21 19 27 19 19 17 19 37 12 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 19 19 6 19 19 19 19 10 19 19 12 12 21 21 0 19 19 19 9 0 20 13 12 19 19 19 37 37 0 19 0 12 12 12 12 12 12 12 12 0 12 12 0 12 12 12 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 11 0 0 0 0 25 29 37 12 0 0 0 0 0 27 0 0 0 10 0 0 10 19 27 21 0 0 0 0 ] /Times-Bold 1000 655360 589824 pf /fi [ 0 0 0 0 0 0 0 0 0 0 0 0 19 19 0 0 10 0 12 12 12 12 12 12 12 19 25 25 19 33 35 27 9 12 21 19 19 31 29 12 12 12 19 25 9 12 9 10 19 19 19 19 19 19 19 19 19 19 12 12 15 25 19 19 34 23 23 25 27 23 23 27 27 12 17 25 21 31 25 27 23 27 23 19 21 27 23 31 23 21 21 15 21 15 12 12 12 19 19 17 19 17 10 19 19 10 10 17 10 27 19 19 19 19 15 15 10 19 17 25 17 17 15 19 33 12 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 19 19 6 19 19 19 19 8 21 19 12 12 19 19 0 19 19 19 9 0 20 13 12 21 21 19 33 37 0 19 0 12 12 12 12 12 12 12 12 0 12 12 0 12 12 12 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 10 0 0 0 0 21 27 35 12 0 0 0 0 0 25 0 0 0 10 0 0 10 19 25 19 0 0 0 0 ] /Times-Italic 1000 655360 589824 pf /fj [ 0 0 0 0 0 0 0 0 0 0 0 0 21 21 0 0 10 0 12 12 12 12 12 12 12 19 25 27 19 33 33 27 9 12 17 19 19 31 29 12 12 12 19 21 9 12 9 10 19 19 19 19 19 19 19 19 19 19 10 10 12 21 17 17 34 27 25 25 27 23 21 27 27 12 15 27 23 33 27 27 21 27 25 21 23 27 27 35 27 27 23 12 17 12 12 12 12 17 19 17 19 17 12 19 19 10 10 19 10 29 19 19 19 19 12 15 10 19 19 27 19 19 17 19 37 12 12 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 19 19 6 19 19 19 19 7 17 19 12 12 21 21 0 19 19 19 9 0 17 13 12 17 17 19 37 37 0 17 0 12 12 12 12 12 12 12 12 0 12 12 0 12 12 12 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 10 0 0 0 0 23 27 33 12 0 0 0 0 0 25 0 0 0 10 0 0 10 19 27 19 0 0 0 0 ] /Times-Roman 1000 655360 589824 pf /fk [ 0 0 0 0 0 0 0 0 0 0 0 0 18 18 0 0 9 0 11 11 11 11 11 11 11 17 22 24 17 30 30 24 8 11 15 17 17 28 26 11 11 11 17 19 8 11 8 9 17 17 17 17 17 17 17 17 17 17 9 9 11 19 15 15 31 24 22 22 24 20 18 24 24 11 13 24 20 30 24 24 18 24 22 18 20 24 24 31 24 24 20 11 15 11 11 11 11 15 17 15 17 15 11 17 17 9 9 17 9 26 17 17 17 17 11 13 9 17 17 24 17 17 15 17 33 11 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 17 17 6 17 17 17 17 6 15 17 11 11 18 18 0 17 17 17 8 0 15 12 11 15 15 17 33 33 0 15 0 11 11 11 11 11 11 11 11 0 11 11 0 11 11 11 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 0 9 0 0 0 0 20 24 30 10 0 0 0 0 0 22 0 0 0 9 0 0 9 17 24 17 0 0 0 0 ] /Times-Roman 1000 655360 524288 pf end TeXDict begin @letter %%Page: 1 18 bop 1779 162 a fg(1)150 307 y fa(1)60 b(Intr)o(oduction)150 403 y fg(This)8 b (document)f(is)h(one)g(of)f(two)g(tutorials)f(designed)h(to)h(teach)g(basic)g (Mach)h(programming)d(skills.)14 b(This)8 b(manual)150 453 y(demonstrates)13 b (the)g(use)g(of)g(the)g(C)g(Threads)h(library)d(primitives)h(in)g(writing)f (a)j(multi-threaded)d(program)i(and)150 503 y(the)e(use)h(of)g(the)f(Mach)h (Interface)g(Generator)g(\(MIG\))f(to)g(generate)h(remote)g(procedure)g(calls) f(for)g(interprocess)150 553 y(communication.)32 b(It)16 b(also)g(includes)f (a)i(\014nal)f(section)g(on)f(where)i(at)f(CMU)f(to)h(\014nd)g(the)f(include) h(\014les)g(and)150 602 y(libraries)d(that)h(comprise)h(the)f(Mach)h(environm\ ent)e(as)i(well)f(as)h(procedures)g(for)e(obtaining)g(these)h(\014les)h(and) 150 652 y(setting)9 b(up)h(the)g(correct)h(user)f(environment.)212 704 y(The) 18 b(reader)h(should)d(be)i(familiar)f(with)f(the)h(basic)h(Mach)g(abstractio\ ns)f(of)g(ports,)i(messages,)j(virtual)150 754 y(memory)m(,)c(tasks)e(and)f (threads)h(before)g(reading)f(this)f(document.)32 b(The)16 b(introduction)d (to)i(the)g(other)g(tutorial)150 803 y(document,)10 b fe(A)h(Pr)n(ogrammer)r (')-5 b(s)11 b(Guide)e(to)h(the)g(Mach)g(System)h(Calls)p fg(,)e(explains)h (these)h(concepts.)150 953 y fa(2)60 b(C)15 b(Thr)o(eads:)22 b(Master)14 b (Thr)o(ead)g(Spawning)i(Concurr)o(ent)d(Slaves)150 1049 y fg(The)e(C)g(thread\ s)g(package)g(is)g(a)g(runtime)f(library)g(that)g(provides)g(a)h(C)f(language) h(interface)g(to)f(a)i(number)e(of)h(low)150 1099 y(level,)j(Mach)g(primitive\ s)e(for)h(manipulating)e(threads)j(of)f(control.)23 b(The)14 b(constructs)f (provided)f(are:)22 b(forking)150 1149 y(and)12 b(joining)e(of)i(threads,)i (protection)c(of)i(critical)g(regions)g(with)f(mutex)h(variables,)h(and)g(syn\ chronization)d(by)150 1198 y(means)g(of)e(condition)e(variables.)16 b(For)8 b (a)h(complete)g(description)e(of)h(the)h(C)f(threads)g(package)i(see)g(the)e fe(C)g(Thr)n(eads)150 1248 y fg(manual)k(by)f(Cooper)f(and)i(Draves.)20 b(It) 11 b(is)g(highly)e(recommended)k(that)e(a)h(programmer)g(doing)e(multi-thread\ ed)150 1298 y(applications)f(use)i(the)f(C)g(threads)g(routines)f(rather)h (than)g(the)g(Mach)h(system)g(calls.)16 b(The)11 b(C)f(threads)g(package)h (is)150 1348 y(designed)f(to)g(provide)f(a)i(more)g(natural)f(set)g(of)g(prim\ itives)f(for)h(multi-threaded)f(applications)g(and)h(is)g(carefully)150 1398 y (optimized)f(to)h(produce)g(the)g(most)g(ef)o(\014cient)h(use)g(of)f(the)g (system)h(calls.)212 1449 y(The)g(program)e(at)h(the)g(end)g(of)f(this)g(sect\ ion)g(is)h(an)g(example)h(of)e(how)h(to)f(structure)g(a)h(program)g(with)e (a)j(single)150 1499 y(master)j(thread)f(which)f(spawns)i(a)f(number)g(of)g (concurrent)g(slaves.)24 b(The)14 b(master)g(thread)f(waits)f(until)g(all)g (the)150 1549 y(slaves)f(have)g(\014nished)f(to)g(exit.)16 b(A)11 b(random)f (number)h(generator)f(is)h(used)f(to)g(determine)h(the)f(`life')g(of)g(the)h (slave)150 1599 y(processes.)20 b(Once)12 b(created)g(the)f(slave)h(processes) g(in)f(this)f(example)i(simply)f(loop)f(calling)g(a)i(cthread)g(function)150 1649 y(making)k(the)g(processor)g(available)g(to)f(other)h(threads.)33 b(The) 16 b(random)g(number)g(generator)g(determines)g(the)150 1698 y(length)8 b(of) g(this)g(loop.)14 b(In)8 b(a)h(more)h(useful)e(version)g(of)g(this)g(program,) h(each)h(slave)f(process)g(would)f(do)g(something)150 1748 y(while)i(looping.) 212 1800 y(In)g(order)f(for)h(the)f(master)i(thread)e(to)h(determine)g(when)f (all)h(of)f(the)h(slaves)g(have)h(exited,)e(a)i fc(count)e fg(variable)150 1850 y(is)h(needed)h(to)f(keep)h(track)f(of)g(the)g(number)g(of)g(current)g (threads.)16 b(This)11 b fc(count)f fg(is)g(incremented)g(by)g(the)g(master) 150 1899 y(with)j(each)i(creation)e(of)h(a)g(slave.)27 b(Each)15 b(slave)g (decrements)g(the)e fc(count)h fg(when)g(it)f(exits.)26 b(Because)15 b(two)e (or)150 1949 y(more)f(threads)f(may)g(be)h(trying)d(to)i(access)i(the)e fc (count)g fg(at)g(the)g(same)i(time,)e(a)h(mutex)f(called)h fc(lock)e fg(is)h (used)h(to)150 1999 y(provide)c(exclusive)g(access)j(to)e fc(count)p fg(.)15 b (If)8 b(any)h(thread)g(wants)f(to)h(access)h(the)f fc(count)g fg(variable,)g (it)f(should)f(\014rst)150 2049 y(lock)12 b(the)g(mutex.)23 b(Consequently)10 b(when)j(the)f(mutex)g(is)h(locked,)g(any)f(thread)h(wanting)e(the)h fc(count) g fg(variable)150 2099 y(must)e(wait)g(until)e(the)j(mutex)f(is)g(unlocked.) 212 2150 y(Condition)e(variables)i(are)h(used)g(to)f(provide)f(synchronizatio\ n)g(between)i(threads,)f(e.g)h(one)g(thread)f(wishes)150 2200 y(to)j(wait)g (until)f(another)h(thread)g(has)h(\014nished)f(doing)g(something.)24 b(Every) 14 b(condition)e(variable)h(is)g(associated)150 2250 y(with)f(a)h(mutex.)23 b (The)13 b(condition)e(variable)h(represents)h(a)h(boolean)e(state)h(of)f(the) h(shared)g(data)g(that)f(the)g(mutex)150 2300 y(protects.)j(In)8 b(this)f(exa\ mple)i(after)f(all)g(of)g(the)g(slave)h(threads)f(have)h(been)g(created,)h (the)e(master)h(thread)f(waits)g(until)150 2350 y(the)i fc(count)h fg(variabl\ e)f(is)g(equal)h(to)f(zero.)18 b(A)10 b(condition)f(variable)h fc(done)g fg (is)h(used)g(to)f(represent)h(the)f(possibility)150 2399 y(that)f(the)g fc (count)h fg(may)g(equal)g(zero.)16 b(Just)9 b(before)h(a)g(slave)g(thread)g (exits,)f(it)g(signals)g(the)h(condition)d fc(done)j fg(since)150 2449 y(it)h (may)i(be)g(the)f(last)g(slave)g(executing.)22 b(The)12 b(master)h(thread)f (loops)g(waiting)f(on)g(the)h(condition)f fc(done)p fg(.)21 b(Each)g eop %%Page: 0 19 bop 265 307 a fa(A)15 b(Pr)o(ogrammer)q(')n(s)d(Guide)i(to)h(the)f(Mach)h (User)g(Envir)o(onment)832 507 y fg(Linda)10 b(R.)h(W)m(almer)812 557 y(Mary) f(R.)h(Thompson)697 757 y(Department)f(of)g(Computer)f(Science)740 806 y(Carn\ egie-Mellon)g(University)798 856 y(Pittsbur)o(gh,)g(P)l(A)h(15213)716 1056 y fd(V)l(ersion)h(of:)k(7)10 b(November)h(1989)905 1523 y fh(Abstract)355 1592 y fj(This)k(document)f(is)i(one)e(of)i(two)g(tutorials)g(designed)d(to)j(teach) e(basic)h(Mach)f(programming)299 1637 y(skills.)26 b(This)13 b(manual)f(demon\ strates)f(the)i(use)f(of)h(the)g(C)g(Threads)f(library)i(primitives)f(in)h (writing)299 1683 y(a)d(multi-threaded)g(program)f(and)g(the)h(use)e(of)i(the) g(Mach)f(Interface)g(Generator)h(\(MIG\))h(to)f(generate)299 1729 y(remote)f (procedure)d(calls)i(for)h(interprocess)e(communication.)355 1774 y(The)14 b (reader)f(should)g(be)h(familiar)h(with)g(the)f(basic)f(Mach)g(abstractions)g (of)i(ports,)g(messages,)299 1820 y(virtual)f(memory)n(,)f(tasks)e(and)h(thre\ ads.)23 b(The)12 b(introduction)g(to)h(the)f(companion)f(document)g(to)i(this) 299 1866 y(one,)c fi(A)g(Pr)o(ogrammer)q(')-5 b(s)7 b(Guide)h(to)i(the)f(Mach) f(System)g(Calls)p fj(,)i(explains)e(these)g(concepts.)355 1911 y(Comments,)h (suggestions)e(and)h(additions)g(to)i(this)f(document)f(are)h(welcome.)212 2171 y fk(The)15 b(material)h(developed)d(under)h(this)h(subcontract)f(was)h (or)g(is)h(sponsored)d(by)h(the)h(Defense)g(Advanced)e(Research)h(Projects) 150 2210 y(Agency)8 b(\(DoD\),)h(ARP)m(A)h(order)e(4864,)h(monitored)f(by)g (the)h(Space)g(and)f(Naval)h(W)m(arfare)h(Systems)f(Command)e(under)h(Contrac\ t)h(Number)150 2249 y(N00039-87-C-025)o(1.)212 2299 y(The)14 b(views)g(and)g (conclusions)e(contained)h(in)h(this)h(document)d(are)i(those)g(of)g(the)g (authors)g(and)f(should)g(not)h(be)g(interpreted)f(as)150 2349 y(representing) 5 b(of)o(\014cial)j(policies,)f(either)g(expressed)e(or)i(implied,)g(of)g(the) g(Defense)f(Advanced)f(Research)h(Projects)h(Agency)e(or)i(Department)150 2399 y(of)13 b(the)g(Navy)n(,)h(Space)f(and)f(Naval)h(W)m(arfare)h(Systems)f(Comma\ nd,)g(or)h(Carnegie-Mellon)d(University)n(,)j(unless)f(designated)e(by)i(othe\ r)150 2449 y(documentation.)g eop %%Page: 1 20 bop 1788 162 a fg(i)150 307 y fa(Contents)150 400 y fd(1)41 b(Intr)o(oductio\ n)1342 b(1)150 491 y(2)41 b(C)11 b(Thr)o(eads:)16 b(Master)11 b(Thr)o(ead)g (Spawning)f(Concurr)o(ent)i(Slaves)558 b(1)212 541 y fg(2.1)44 b(Initializing) 7 b(the)j(C)g(Threads)i(Package)22 b ff(:)e(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg (2)212 591 y(2.2)44 b(Allocation)8 b(of)i(a)h(Mutex)f(V)-5 b(ariable)14 b ff (:)21 b(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg(3)212 641 y(2.3)44 b(Locking)9 b(a)i(Mutex)f(V)-5 b(ariable)32 b ff(:)20 b(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)57 b fg(3)212 690 y(2.4)44 b(Unlocking)8 b(a)j(Mutex)f(V)-5 b(ariable) 27 b ff(:)20 b(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg(3)212 740 y(2.5)44 b(Allocation)8 b(of)i(a)h(Condition)d(V)-5 b(ariable)21 b ff(:)f(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)57 b fg(3)212 790 y(2.6)44 b(W)m(aiting)9 b(on)g(a)i(Condition)g ff (:)21 b(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg(4)212 840 y (2.7)44 b(Signalling)8 b(a)j(Condition)22 b ff(:)f(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)57 b fg(4)212 890 y(2.8)44 b(Forking)9 b(a)h(C)g(Threa\ d)i ff(:)20 b(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg (4)212 939 y(2.9)44 b(Detaching)10 b(a)h(C)f(Thread)36 b ff(:)21 b(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg(5)212 989 y(2.10)23 b(Y)n(ield\ ing)8 b(the)i(Processor)h(to)f(other)f(Threads)35 b ff(:)20 b(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg (5)212 1039 y(2.11)23 b(Exiting)8 b(a)j(C)f(Thread)21 b ff(:)f(:)g(:)h(:)f (:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg(5)212 1089 y(2.12)23 b(Exa\ mple)11 b(V)-5 b(,)10 b(masterslave.c)40 b ff(:)20 b(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)57 b fg(6)150 1180 y fd(3)41 b(MIG)11 b(-)f(The)h(Mach)g(Inter\ face)h(Generator)898 b(9)212 1230 y fg(3.1)44 b(MIG)10 b(De\014nition)f(\014l\ e)14 b ff(:)20 b(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)57 b fg (9)212 1280 y(3.2)44 b(Server)10 b(main)h(program)16 b ff(:)k(:)h(:)f(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fg(10)212 1330 y(3.3)44 b(Server)10 b (message)i(dispatch)e(code)34 b ff(:)21 b(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fg (14)212 1379 y(3.4)44 b(Server)10 b(procedures)37 b ff(:)20 b(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fg(16)212 1429 y(3.5)44 b(User)10 b(Side)j ff(:)21 b(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h (:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f (:)g(:)h(:)f(:)g(:)36 b fg(17)150 1521 y fd(4)41 b(General)12 b(Mach)e(Inform\ ation)1063 b(18)212 1570 y fg(4.1)44 b(Structure)9 b(of)h(the)g(Mach)h(T)o (ree)19 b ff(:)h(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fg(18)212 1620 y (4.2)44 b(Where)11 b(to)e(Find)h(Examples)h(and)f(Manuals)23 b ff(:)d(:)g(:)g (:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f (:)g(:)36 b fg(18)212 1670 y(4.3)44 b(Setting)9 b(Up)h(Search)h(Paths)32 b ff (:)20 b(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fg(19)212 1720 y(4.4) 44 b(Mach)11 b(Libraries)17 b ff(:)j(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h (:)f(:)g(:)h(:)f(:)g(:)36 b fg(19)212 1770 y(4.5)44 b(Mach)11 b(Include)f(Fil\ es)16 b ff(:)k(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g (:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fg (19)212 1819 y(4.6)44 b(Mach)11 b(Information/Question)o(s)k ff(:)20 b(:)h (:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)g(:)h(:)f(:)g(:)h(:)f(:)g (:)g(:)h(:)f(:)g(:)h(:)f(:)g(:)36 b fg(19)g eop eos end %%EOF