home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MAILBOX.ZIP / MPTSK.TEX / node12_ct.html < prev    next >
LaTeX Document  |  1988-06-27  |  7.0 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

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

You can browse this item here: node12_ct.html

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
90% dexvert Hypertext Markup Language File (text/html) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file HTML document text default (weak)
99% file LaTeX document text default
98% file exported SGML document text default
97% file exported SGML document, ASCII text, with CRLF, LF line terminators default
80% TrID HyperText Markup Language with DOCTYPE default
19% TrID HyperText Markup Language default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% gt2 HTML (Hyper Text Markup Language) Datei default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime text/html default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 3c 21 44 4f 43 54 59 50 | 45 20 48 54 4d 4c 20 50 |<!DOCTYP|E HTML P|
|00000010| 55 42 4c 49 43 20 22 2d | 2f 2f 57 33 43 2f 2f 44 |UBLIC "-|//W3C//D|
|00000020| 54 44 20 48 54 4d 4c 20 | 33 2e 32 20 46 69 6e 61 |TD HTML |3.2 Fina|
|00000030| 6c 2f 2f 65 6e 22 3e 0a | 0a 3c 21 2d 2d 43 6f 6e |l//en">.|.<!--Con|
|00000040| 76 65 72 74 65 64 20 77 | 69 74 68 20 4c 61 54 65 |verted w|ith LaTe|
|00000050| 58 32 48 54 4d 4c 20 32 | 30 32 32 20 28 52 65 6c |X2HTML 2|022 (Rel|
|00000060| 65 61 73 65 64 20 4a 61 | 6e 75 61 72 79 20 31 2c |eased Ja|nuary 1,|
|00000070| 20 32 30 32 32 29 20 2d | 2d 3e 0a 3c 48 54 4d 4c | 2022) -|->.<HTML|
|00000080| 20 6c 61 6e 67 3d 22 65 | 6e 22 3e 0a 3c 48 45 41 | lang="e|n">.<HEA|
|00000090| 44 3e 0a 3c 54 49 54 4c | 45 3e 43 6f 6e 74 65 6e |D>.<TITL|E>Conten|
|000000a0| 74 73 20 6f 66 20 4d 50 | 54 48 44 3a 20 54 68 65 |ts of MP|THD: The|
|000000b0| 20 43 6f 6e 74 65 78 74 | 20 53 77 69 74 63 68 69 | Context| Switchi|
|000000c0| 6e 67 20 4c 61 79 65 72 | 3c 2f 54 49 54 4c 45 3e |ng Layer|</TITLE>|
|000000d0| 0a 0a 3c 4d 45 54 41 20 | 48 54 54 50 2d 45 51 55 |..<META |HTTP-EQU|
|000000e0| 49 56 3d 22 43 6f 6e 74 | 65 6e 74 2d 54 79 70 65 |IV="Cont|ent-Type|
|000000f0| 22 20 43 4f 4e 54 45 4e | 54 3d 22 74 65 78 74 2f |" CONTEN|T="text/|
|00000100| 68 74 6d 6c 3b 20 63 68 | 61 72 73 65 74 3d 75 74 |html; ch|arset=ut|
|00000110| 66 2d 38 22 3e 0a 3c 4d | 45 54 41 20 4e 41 4d 45 |f-8">.<M|ETA NAME|
|00000120| 3d 22 76 69 65 77 70 6f | 72 74 22 20 43 4f 4e 54 |="viewpo|rt" CONT|
|00000130| 45 4e 54 3d 22 77 69 64 | 74 68 3d 64 65 76 69 63 |ENT="wid|th=devic|
|00000140| 65 2d 77 69 64 74 68 2c | 20 69 6e 69 74 69 61 6c |e-width,| initial|
|00000150| 2d 73 63 61 6c 65 3d 31 | 2e 30 22 3e 0a 3c 4d 45 |-scale=1|.0">.<ME|
|00000160| 54 41 20 4e 41 4d 45 3d | 22 47 65 6e 65 72 61 74 |TA NAME=|"Generat|
|00000170| 6f 72 22 20 43 4f 4e 54 | 45 4e 54 3d 22 4c 61 54 |or" CONT|ENT="LaT|
|00000180| 65 58 32 48 54 4d 4c 20 | 76 32 30 32 32 22 3e 0a |eX2HTML |v2022">.|
|00000190| 0a 3c 4c 49 4e 4b 20 52 | 45 4c 3d 22 53 54 59 4c |.<LINK R|EL="STYL|
|000001a0| 45 53 48 45 45 54 22 20 | 48 52 45 46 3d 22 4d 50 |ESHEET" |HREF="MP|
|000001b0| 54 53 4b 2e 63 73 73 22 | 3e 0a 0a 3c 4c 49 4e 4b |TSK.css"|>..<LINK|
|000001c0| 20 52 45 4c 3d 22 6e 65 | 78 74 22 20 48 52 45 46 | REL="ne|xt" HREF|
|000001d0| 3d 22 6e 6f 64 65 31 33 | 5f 6d 6e 2e 68 74 6d 6c |="node13|_mn.html|
|000001e0| 22 3e 0a 3c 4c 49 4e 4b | 20 52 45 4c 3d 22 70 72 |">.<LINK| REL="pr|
|000001f0| 65 76 69 6f 75 73 22 20 | 48 52 45 46 3d 22 6e 6f |evious" |HREF="no|
|00000200| 64 65 31 31 5f 6d 6e 2e | 68 74 6d 6c 22 3e 0a 3c |de11_mn.|html">.<|
|00000210| 4c 49 4e 4b 20 52 45 4c | 3d 22 75 70 22 20 48 52 |LINK REL|="up" HR|
|00000220| 45 46 3d 22 6e 6f 64 65 | 39 5f 6d 6e 2e 68 74 6d |EF="node|9_mn.htm|
|00000230| 6c 22 3e 0a 3c 4c 49 4e | 4b 20 52 45 4c 3d 22 6e |l">.<LIN|K REL="n|
|00000240| 65 78 74 22 20 48 52 45 | 46 3d 22 6e 6f 64 65 31 |ext" HRE|F="node1|
|00000250| 33 5f 6d 6e 2e 68 74 6d | 6c 22 3e 0a 3c 2f 48 45 |3_mn.htm|l">.</HE|
|00000260| 41 44 3e 0a 20 0a 3c 42 | 4f 44 59 20 62 67 63 6f |AD>. .<B|ODY bgco|
|00000270| 6c 6f 72 3d 22 23 66 66 | 66 66 66 66 22 20 74 65 |lor="#ff|ffff" te|
|00000280| 78 74 3d 22 23 30 30 30 | 30 30 30 22 20 6c 69 6e |xt="#000|000" lin|
|00000290| 6b 3d 22 23 39 39 34 34 | 45 45 22 20 76 6c 69 6e |k="#9944|EE" vlin|
|000002a0| 6b 3d 22 23 30 30 30 30 | 66 66 22 20 61 6c 69 6e |k="#0000|ff" alin|
|000002b0| 6b 3d 22 23 30 30 66 66 | 30 30 22 3e 0a 0a 3c 48 |k="#00ff|00">..<H|
|000002c0| 32 3e 3c 41 20 49 44 3d | 22 53 45 43 54 49 4f 4e |2><A ID=|"SECTION|
|000002d0| 30 30 30 34 33 30 30 30 | 30 30 30 30 30 30 30 30 |00043000|00000000|
|000002e0| 30 30 30 30 22 3e 0a 4d | 50 54 48 44 3a 20 20 54 |0000">.M|PTHD: T|
|000002f0| 68 65 20 43 6f 6e 74 65 | 78 74 20 53 77 69 74 63 |he Conte|xt Switc|
|00000300| 68 69 6e 67 20 4c 61 79 | 65 72 3c 2f 41 3e 0a 3c |hing Lay|er</A>.<|
|00000310| 2f 48 32 3e 0a 0a 3c 50 | 3e 0a 45 73 73 65 6e 74 |/H2>..<P|>.Essent|
|00000320| 69 61 6c 20 74 6f 20 61 | 6e 79 20 6d 75 6c 74 69 |ial to a|ny multi|
|00000330| 74 61 73 6b 65 72 20 69 | 73 20 74 68 65 20 61 62 |tasker i|s the ab|
|00000340| 69 6c 69 74 79 20 74 6f | 20 73 77 69 74 63 68 20 |ility to| switch |
|00000350| 74 68 65 20 70 72 6f 63 | 65 73 73 6f 72 27 73 0d |the proc|essor's.|
|00000360| 0a 63 6f 6e 74 65 78 74 | 20 66 72 6f 6d 20 6f 6e |.context| from on|
|00000370| 65 20 70 72 6f 63 65 73 | 73 20 74 6f 20 61 6e 6f |e proces|s to ano|
|00000380| 74 68 65 72 2e 20 20 54 | 72 61 64 69 74 69 6f 6e |ther. T|radition|
|00000390| 61 6c 20 6d 75 6c 74 69 | 74 61 73 6b 65 72 73 20 |al multi|taskers |
|000003a0| 64 6f 0d 0a 74 68 69 73 | 20 62 79 20 68 61 76 69 |do..this| by havi|
|000003b0| 6e 67 20 69 6e 74 65 72 | 72 75 70 74 20 68 61 6e |ng inter|rupt han|
|000003c0| 64 6c 65 72 73 20 73 61 | 76 65 20 74 68 65 20 73 |dlers sa|ve the s|
|000003d0| 74 61 74 65 20 6f 66 20 | 70 72 6f 63 65 73 73 6f |tate of |processo|
|000003e0| 72 20 62 79 0d 0a 70 75 | 73 68 69 6e 67 20 69 74 |r by..pu|shing it|
|000003f0| 20 6f 6e 20 74 68 65 20 | 73 74 61 63 6b 20 77 68 | on the |stack wh|
|00000400| 65 6e 20 74 68 65 79 20 | 61 72 65 20 69 6e 76 6f |en they |are invo|
|00000410| 6b 65 64 2e 20 20 54 68 | 69 73 20 69 73 20 61 6e |ked. Th|is is an|
|00000420| 20 65 66 66 69 63 69 65 | 6e 74 0d 0a 62 75 74 20 | efficie|nt..but |
|00000430| 63 6f 6d 70 6c 65 78 20 | 61 6e 64 20 6d 61 63 68 |complex |and mach|
|00000440| 69 6e 65 20 64 65 70 65 | 6e 64 65 6e 74 20 61 70 |ine depe|ndent ap|
|00000450| 70 72 6f 61 63 68 2e 20 | 20 54 68 65 20 4d 50 54 |proach. | The MPT|
|00000460| 48 44 20 6c 61 79 65 72 | 20 61 63 68 69 65 76 65 |HD layer| achieve|
|00000470| 73 0d 0a 74 68 65 20 73 | 61 6d 65 20 65 66 66 65 |s..the s|ame effe|
|00000480| 63 74 20 69 6e 20 61 20 | 70 6f 72 74 61 62 6c 65 |ct in a |portable|
|00000490| 20 77 61 79 20 74 68 61 | 74 20 69 73 20 65 61 73 | way tha|t is eas|
|000004a0| 79 20 74 6f 20 75 6e 64 | 65 72 73 74 61 6e 64 2e |y to und|erstand.|
|000004b0| 0a 0a 3c 50 3e 0a 54 68 | 65 20 4d 50 54 48 44 20 |..<P>.Th|e MPTHD |
|000004c0| 6c 61 79 65 72 20 69 6e | 74 72 6f 64 75 63 65 73 |layer in|troduces|
|000004d0| 20 74 68 65 20 6e 6f 74 | 69 6f 6e 20 6f 66 20 61 | the not|ion of a|
|000004e0| 6e 20 74 68 72 65 61 64 | 2c 20 61 6e 64 20 69 6e |n thread|, and in|
|000004f0| 64 65 70 65 6e 64 65 6e | 74 0d 0a 74 68 72 65 61 |dependen|t..threa|
|00000500| 64 20 6f 66 20 65 78 65 | 63 75 74 69 6f 6e 2e 20 |d of exe|cution. |
|00000510| 20 4c 69 6b 65 20 61 20 | 6e 6f 72 6d 61 6c 20 70 | Like a |normal p|
|00000520| 72 6f 63 65 73 73 2c 20 | 61 20 74 68 72 65 61 64 |rocess, |a thread|
|00000530| 20 68 61 73 20 69 74 73 | 20 6f 77 6e 0d 0a 73 74 | has its| own..st|
|00000540| 61 63 6b 20 6f 6e 20 77 | 68 69 63 68 20 69 74 20 |ack on w|hich it |
|00000550| 65 78 65 63 75 74 65 73 | 2e 20 20 57 69 74 68 20 |executes|. With |
|00000560| 69 74 73 20 6f 77 6e 20 | 73 74 61 63 6b 2c 20 74 |its own |stack, t|
|00000570| 68 65 20 73 74 61 74 65 | 20 6f 66 20 74 68 65 0d |he state| of the.|
|00000580| 0a 74 68 72 65 61 64 20 | 63 61 6e 20 62 65 20 73 |.thread |can be s|
|00000590| 61 76 65 64 2c 20 61 6e | 64 20 74 68 65 6e 20 74 |aved, an|d then t|
|000005a0| 68 65 20 74 68 72 65 61 | 64 20 6c 61 74 65 72 20 |he threa|d later |
|000005b0| 72 65 73 75 6d 65 64 20 | 28 73 65 65 0d 0a 69 6c |resumed |(see..il|
|000005c0| 6c 75 73 74 72 61 74 69 | 6f 6e 20 6f 66 20 69 6e |lustrati|on of in|
|000005d0| 74 65 72 6e 61 6c 20 4d | 50 54 48 44 20 64 61 74 |ternal M|PTHD dat|
|000005e0| 61 74 79 70 65 29 2e 0a | 0a 3c 50 3e 0a 54 6f 20 |atype)..|.<P>.To |
|000005f0| 70 65 72 66 6f 72 6d 20 | 74 68 69 73 20 63 6f 6e |perform |this con|
|00000600| 74 65 78 74 20 73 77 69 | 74 63 68 2c 20 74 68 65 |text swi|tch, the|
|00000610| 20 74 68 72 65 61 64 20 | 6d 75 73 74 20 63 61 6c | thread |must cal|
|00000620| 6c 20 74 68 65 0d 0a 3c | 21 2d 2d 20 4d 41 54 48 |l the..<|!-- MATH|
|00000630| 0a 20 24 6d 70 74 68 64 | 5c 5f 73 77 69 74 63 68 |. $mpthd|\_switch|
|00000640| 28 29 24 0a 20 2d 2d 3e | 0a 3c 49 3e 6d 70 74 68 |()$. -->|.<I>mpth|
|00000650| 64 3c 2f 49 3e 3c 49 4d | 47 0a 20 53 54 59 4c 45 |d</I><IM|G. STYLE|
|00000660| 3d 22 68 65 69 67 68 74 | 3a 20 32 35 2e 33 39 65 |="height|: 25.39e|
|00000670| 78 3b 20 76 65 72 74 69 | 63 61 6c 2d 61 6c 69 67 |x; verti|cal-alig|
|00000680| 6e 3a 20 31 35 31 2e 34 | 30 65 78 3b 20 22 20 53 |n: 151.4|0ex; " S|
|00000690| 52 43 3d 22 69 6d 67 34 | 2e 70 6e 67 22 0a 20 41 |RC="img4|.png". A|
|000006a0| 4c 54 3d 22 24 5c 5f 73 | 77 69 74 63 68 24 22 3e |LT="$\_s|witch$">|
|000006b0| 28 29 20 66 75 6e 63 74 | 69 6f 6e 2e 20 20 4e 6f |() funct|ion. No|
|000006c0| 77 20 74 68 65 20 3c 21 | 2d 2d 20 4d 41 54 48 0a |w the <!|-- MATH.|
|000006d0| 20 24 6d 70 74 68 64 5c | 5f 73 77 69 74 63 68 28 | $mpthd\|_switch(|
|000006e0| 29 24 0a 20 2d 2d 3e 0a | 3c 49 3e 6d 70 74 68 64 |)$. -->.|<I>mpthd|
|000006f0| 3c 2f 49 3e 3c 49 4d 47 | 0a 20 53 54 59 4c 45 3d |</I><IMG|. STYLE=|
|00000700| 22 68 65 69 67 68 74 3a | 20 32 35 2e 33 39 65 78 |"height:| 25.39ex|
|00000710| 3b 20 76 65 72 74 69 63 | 61 6c 2d 61 6c 69 67 6e |; vertic|al-align|
|00000720| 3a 20 31 35 31 2e 34 30 | 65 78 3b 20 22 20 53 52 |: 151.40|ex; " SR|
|00000730| 43 3d 22 69 6d 67 34 2e | 70 6e 67 22 0a 20 41 4c |C="img4.|png". AL|
|00000740| 54 3d 22 24 5c 5f 73 77 | 69 74 63 68 24 22 3e 28 |T="$\_sw|itch$">(|
|00000750| 29 20 66 75 6e 63 74 69 | 6f 6e 20 69 73 20 6e 6f |) functi|on is no|
|00000760| 74 20 79 6f 75 72 0d 0a | 6f 72 64 69 6e 61 72 79 |t your..|ordinary|
|00000770| 20 66 75 6e 63 74 69 6f | 6e 2e 20 20 54 68 65 20 | functio|n. The |
|00000780| 3c 21 2d 2d 20 4d 41 54 | 48 0a 20 24 6d 70 74 68 |<!-- MAT|H. $mpth|
|00000790| 64 5c 5f 73 77 69 74 63 | 68 28 29 24 0a 20 2d 2d |d\_switc|h()$. --|
|000007a0| 3e 0a 3c 49 3e 6d 70 74 | 68 64 3c 2f 49 3e 3c 49 |>.<I>mpt|hd</I><I|
|000007b0| 4d 47 0a 20 53 54 59 4c | 45 3d 22 68 65 69 67 68 |MG. STYL|E="heigh|
|000007c0| 74 3a 20 32 35 2e 33 39 | 65 78 3b 20 76 65 72 74 |t: 25.39|ex; vert|
|000007d0| 69 63 61 6c 2d 61 6c 69 | 67 6e 3a 20 31 35 31 2e |ical-ali|gn: 151.|
|000007e0| 34 30 65 78 3b 20 22 20 | 53 52 43 3d 22 69 6d 67 |40ex; " |SRC="img|
|000007f0| 34 2e 70 6e 67 22 0a 20 | 41 4c 54 3d 22 24 5c 5f |4.png". |ALT="$\_|
|00000800| 73 77 69 74 63 68 24 22 | 3e 28 29 20 66 75 6e 63 |switch$"|>() func|
|00000810| 74 69 6f 6e 20 69 73 20 | 73 70 65 63 69 61 6c 2e |tion is |special.|
|00000820| 20 20 4c 69 6b 65 20 61 | 6e 0d 0a 6f 72 64 69 6e | Like a|n..ordin|
|00000830| 61 72 79 20 66 75 6e 63 | 74 69 6f 6e 2c 20 74 68 |ary func|tion, th|
|00000840| 65 20 3c 21 2d 2d 20 4d | 41 54 48 0a 20 24 6d 70 |e <!-- M|ATH. $mp|
|00000850| 74 68 64 5c 5f 73 77 69 | 74 63 68 28 29 24 0a 20 |thd\_swi|tch()$. |
|00000860| 2d 2d 3e 0a 3c 49 3e 6d | 70 74 68 64 3c 2f 49 3e |-->.<I>m|pthd</I>|
|00000870| 3c 49 4d 47 0a 20 53 54 | 59 4c 45 3d 22 68 65 69 |<IMG. ST|YLE="hei|
|00000880| 67 68 74 3a 20 32 35 2e | 33 39 65 78 3b 20 76 65 |ght: 25.|39ex; ve|
|00000890| 72 74 69 63 61 6c 2d 61 | 6c 69 67 6e 3a 20 31 35 |rtical-a|lign: 15|
|000008a0| 31 2e 34 30 65 78 3b 20 | 22 20 53 52 43 3d 22 69 |1.40ex; |" SRC="i|
|000008b0| 6d 67 34 2e 70 6e 67 22 | 0a 20 41 4c 54 3d 22 24 |mg4.png"|. ALT="$|
|000008c0| 5c 5f 73 77 69 74 63 68 | 24 22 3e 28 29 20 63 61 |\_switch|$">() ca|
|000008d0| 6e 20 72 65 74 75 72 6e | 20 74 6f 20 79 6f 75 2e |n return| to you.|
|000008e0| 20 20 4f 72 20 69 74 20 | 63 61 6e 0d 0a 72 65 74 | Or it |can..ret|
|000008f0| 75 72 6e 20 74 6f 20 61 | 6e 79 6f 6e 65 20 65 6c |urn to a|nyone el|
|00000900| 73 65 20 79 6f 75 20 73 | 70 65 63 69 66 79 21 20 |se you s|pecify! |
|00000910| 20 49 6e 64 65 65 64 2c | 20 74 68 65 20 3c 21 2d | Indeed,| the <!-|
|00000920| 2d 20 4d 41 54 48 0a 20 | 24 6d 70 74 68 64 5c 5f |- MATH. |$mpthd\_|
|00000930| 73 77 69 74 63 68 28 29 | 24 0a 20 2d 2d 3e 0a 3c |switch()|$. -->.<|
|00000940| 49 3e 6d 70 74 68 64 3c | 2f 49 3e 3c 49 4d 47 0a |I>mpthd<|/I><IMG.|
|00000950| 20 53 54 59 4c 45 3d 22 | 68 65 69 67 68 74 3a 20 | STYLE="|height: |
|00000960| 32 35 2e 33 39 65 78 3b | 20 76 65 72 74 69 63 61 |25.39ex;| vertica|
|00000970| 6c 2d 61 6c 69 67 6e 3a | 20 31 35 31 2e 34 30 65 |l-align:| 151.40e|
|00000980| 78 3b 20 22 20 53 52 43 | 3d 22 69 6d 67 34 2e 70 |x; " SRC|="img4.p|
|00000990| 6e 67 22 0a 20 41 4c 54 | 3d 22 24 5c 5f 73 77 69 |ng". ALT|="$\_swi|
|000009a0| 74 63 68 24 22 3e 28 29 | 20 66 75 6e 63 74 69 6f |tch$">()| functio|
|000009b0| 6e 0d 0a 63 61 6e 20 72 | 65 74 75 72 6e 20 74 6f |n..can r|eturn to|
|000009c0| 20 3c 45 4d 3e 61 6e 79 | 3c 2f 45 4d 3e 20 61 63 | <EM>any|</EM> ac|
|000009d0| 74 69 76 65 20 63 61 6c | 6c 20 6f 66 20 3c 21 2d |tive cal|l of <!-|
|000009e0| 2d 20 4d 41 54 48 0a 20 | 24 6d 70 74 68 64 5c 5f |- MATH. |$mpthd\_|
|000009f0| 73 77 69 74 63 68 28 29 | 24 0a 20 2d 2d 3e 0a 3c |switch()|$. -->.<|
|00000a00| 49 3e 6d 70 74 68 64 3c | 2f 49 3e 3c 49 4d 47 0a |I>mpthd<|/I><IMG.|
|00000a10| 20 53 54 59 4c 45 3d 22 | 68 65 69 67 68 74 3a 20 | STYLE="|height: |
|00000a20| 32 35 2e 33 39 65 78 3b | 20 76 65 72 74 69 63 61 |25.39ex;| vertica|
|00000a30| 6c 2d 61 6c 69 67 6e 3a | 20 31 35 31 2e 34 30 65 |l-align:| 151.40e|
|00000a40| 78 3b 20 22 20 53 52 43 | 3d 22 69 6d 67 34 2e 70 |x; " SRC|="img4.p|
|00000a50| 6e 67 22 0a 20 41 4c 54 | 3d 22 24 5c 5f 73 77 69 |ng". ALT|="$\_swi|
|00000a60| 74 63 68 24 22 3e 28 29 | 2e 20 20 59 6f 75 20 73 |tch$">()|. You s|
|00000a70| 70 65 63 69 66 79 20 61 | 73 20 61 6e 0d 0a 61 72 |pecify a|s an..ar|
|00000a80| 67 75 6d 65 6e 74 20 74 | 68 65 20 74 68 72 65 61 |gument t|he threa|
|00000a90| 64 20 79 6f 75 20 77 61 | 6e 74 20 69 74 20 74 6f |d you wa|nt it to|
|00000aa0| 20 72 65 74 75 72 6e 20 | 74 6f 2c 20 61 6e 64 20 | return |to, and |
|00000ab0| 72 65 74 75 72 6e 73 20 | 66 72 6f 6d 20 3c 45 4d |returns |from <EM|
|00000ac0| 3e 0d 0a 74 68 61 74 3c | 2f 45 4d 3e 20 74 68 72 |>..that<|/EM> thr|
|00000ad0| 65 61 64 27 73 20 63 61 | 6c 6c 20 6f 66 20 3c 21 |ead's ca|ll of <!|
|00000ae0| 2d 2d 20 4d 41 54 48 0a | 20 24 6d 70 74 68 64 5c |-- MATH.| $mpthd\|
|00000af0| 5f 73 77 69 74 63 68 28 | 29 24 0a 20 2d 2d 3e 0a |_switch(|)$. -->.|
|00000b00| 3c 49 3e 6d 70 74 68 64 | 3c 2f 49 3e 3c 49 4d 47 |<I>mpthd|</I><IMG|
|00000b10| 0a 20 53 54 59 4c 45 3d | 22 68 65 69 67 68 74 3a |. STYLE=|"height:|
|00000b20| 20 32 35 2e 33 39 65 78 | 3b 20 76 65 72 74 69 63 | 25.39ex|; vertic|
|00000b30| 61 6c 2d 61 6c 69 67 6e | 3a 20 31 35 31 2e 34 30 |al-align|: 151.40|
|00000b40| 65 78 3b 20 22 20 53 52 | 43 3d 22 69 6d 67 34 2e |ex; " SR|C="img4.|
|00000b50| 70 6e 67 22 0a 20 41 4c | 54 3d 22 24 5c 5f 73 77 |png". AL|T="$\_sw|
|00000b60| 69 74 63 68 24 22 3e 28 | 29 2e 20 20 49 6e 20 66 |itch$">(|). In f|
|00000b70| 61 63 74 20 69 74 20 74 | 65 6c 6c 73 20 74 68 61 |act it t|ells tha|
|00000b80| 74 20 74 68 72 65 61 64 | 0d 0a 28 76 69 61 20 69 |t thread|..(via i|
|00000b90| 74 73 20 72 65 74 75 72 | 6e 65 64 20 61 72 67 75 |ts retur|ned argu|
|00000ba0| 6d 65 6e 74 29 20 74 68 | 65 20 74 68 72 65 61 64 |ment) th|e thread|
|00000bb0| 20 74 68 61 74 20 73 77 | 69 74 63 68 65 64 20 74 | that sw|itched t|
|00000bc0| 6f 20 74 68 65 6d 2e 20 | 20 28 53 65 65 0d 0a 69 |o them. | (See..i|
|00000bd0| 6c 6c 75 73 74 72 61 74 | 69 6f 6e 29 2e 0a 0a 3c |llustrat|ion)...<|
|00000be0| 50 3e 0a 0a 3c 44 49 56 | 20 63 6c 61 73 73 3d 22 |P>..<DIV| class="|
|00000bf0| 43 45 4e 54 45 52 22 3e | 3c 41 20 49 44 3d 22 31 |CENTER">|<A ID="1|
|00000c00| 30 32 22 3e 3c 2f 41 3e | 0a 3c 54 41 42 4c 45 3e |02"></A>|.<TABLE>|
|00000c10| 0a 3c 43 41 50 54 49 4f | 4e 20 63 6c 61 73 73 3d |.<CAPTIO|N class=|
|00000c20| 22 42 4f 54 54 4f 4d 22 | 3e 3c 53 54 52 4f 4e 47 |"BOTTOM"|><STRONG|
|00000c30| 3e 46 69 67 75 72 65 3a | 3c 2f 53 54 52 4f 4e 47 |>Figure:|</STRONG|
|00000c40| 3e 0a 4d 50 54 48 44 3a | 20 43 6f 6e 74 65 78 74 |>.MPTHD:| Context|
|00000c50| 20 53 77 69 74 63 68 69 | 6e 67 20 49 6c 6c 75 73 | Switchi|ng Illus|
|00000c60| 74 72 61 74 69 6f 6e 3c | 2f 43 41 50 54 49 4f 4e |tration<|/CAPTION|
|00000c70| 3e 0a 3c 54 52 3e 3c 54 | 44 3e 3c 49 4d 47 0a 20 |>.<TR><T|D><IMG. |
|00000c80| 53 54 59 4c 45 3d 22 68 | 65 69 67 68 74 3a 20 33 |STYLE="h|eight: 3|
|00000c90| 31 34 2e 30 30 65 78 3b | 20 22 20 53 52 43 3d 22 |14.00ex;| " SRC="|
|00000ca0| 69 6d 67 35 2e 70 6e 67 | 22 0a 20 41 4c 54 3d 22 |img5.png|". ALT="|
|00000cb0| 5c 62 65 67 69 6e 7b 66 | 69 67 75 72 65 7d 0a 5c |\begin{f|igure}.\|
|00000cc0| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0a |begin{ve|rbatim}.|
|00000cd0| 54 68 72 65 61 64 20 41 | 20 43 6f 6e 74 72 6f 6c |Thread A| Control|
|00000ce0| 20 46 6c 6f 77 20 54 68 | 72 65 61 64 20 42 0a 2d | Flow Th|read B.-|
|00000cf0| 2d 2d 2d 2d 2d 2d 2e 2e | 2e 0a 2e 2e 2e 74 20 3a |------..|.....t :|
|00000d00| 0a 3a 20 56 20 3a 0a 4f | 75 74 70 75 74 3a 20 27 |.: V :.O|utput: '|
|00000d10| 27 48 65 6c 6c 6f 2c 20 | 74 68 65 72 65 21 27 27 |'Hello, |there!''|
|00000d20| 0a 2d 2d 2d 2d 2d 2d 5c | 65 6e 64 7b 76 65 72 62 |.------\|end{verb|
|00000d30| 61 74 69 6d 7d 0a 5c 65 | 6e 64 7b 66 69 67 75 72 |atim}.\e|nd{figur|
|00000d40| 65 7d 22 3e 3c 2f 54 44 | 3e 3c 2f 54 52 3e 0a 3c |e}"></TD|></TR>.<|
|00000d50| 2f 54 41 42 4c 45 3e 0a | 3c 2f 44 49 56 3e 0a 0a |/TABLE>.|</DIV>..|
|00000d60| 3c 50 3e 0a 54 68 65 20 | 3c 21 2d 2d 20 4d 41 54 |<P>.The |<!-- MAT|
|00000d70| 48 0a 20 24 6d 70 74 68 | 64 5c 5f 73 77 69 74 63 |H. $mpth|d\_switc|
|00000d80| 68 28 29 24 0a 20 2d 2d | 3e 0a 3c 49 3e 6d 70 74 |h()$. --|>.<I>mpt|
|00000d90| 68 64 3c 2f 49 3e 3c 49 | 4d 47 0a 20 53 54 59 4c |hd</I><I|MG. STYL|
|00000da0| 45 3d 22 68 65 69 67 68 | 74 3a 20 32 35 2e 33 39 |E="heigh|t: 25.39|
|00000db0| 65 78 3b 20 76 65 72 74 | 69 63 61 6c 2d 61 6c 69 |ex; vert|ical-ali|
|00000dc0| 67 6e 3a 20 31 35 31 2e | 34 30 65 78 3b 20 22 20 |gn: 151.|40ex; " |
|00000dd0| 53 52 43 3d 22 69 6d 67 | 34 2e 70 6e 67 22 0a 20 |SRC="img|4.png". |
|00000de0| 41 4c 54 3d 22 24 5c 5f | 73 77 69 74 63 68 24 22 |ALT="$\_|switch$"|
|00000df0| 3e 28 29 20 61 6c 73 6f | 20 77 6f 72 6b 73 20 66 |>() also| works f|
|00000e00| 69 6e 65 20 69 6e 20 61 | 20 6d 75 6c 74 69 70 72 |ine in a| multipr|
|00000e10| 6f 63 65 73 73 6f 72 20 | 65 6e 76 69 72 6f 6e 6d |ocessor |environm|
|00000e20| 65 6e 74 2e 20 20 49 66 | 0d 0a 61 6e 6f 74 68 65 |ent. If|..anothe|
|00000e30| 72 20 70 72 6f 63 65 73 | 73 6f 72 20 69 73 20 65 |r proces|sor is e|
|00000e40| 78 65 63 75 74 69 6e 67 | 20 61 20 74 68 72 65 61 |xecuting| a threa|
|00000e50| 64 20 77 68 65 6e 20 79 | 6f 75 20 73 77 69 74 63 |d when y|ou switc|
|00000e60| 68 20 74 6f 20 69 74 2c | 20 69 74 0d 0a 77 69 6c |h to it,| it..wil|
|00000e70| 6c 20 77 61 69 74 20 75 | 6e 74 69 6c 20 74 68 65 |l wait u|ntil the|
|00000e80| 20 6f 74 68 65 72 20 70 | 72 6f 63 65 73 73 6f 72 | other p|rocessor|
|00000e90| 20 73 77 69 74 63 68 65 | 73 20 6f 75 74 20 6f 66 | switche|s out of|
|00000ea0| 20 74 68 65 20 74 68 72 | 65 61 64 20 62 65 66 6f | the thr|ead befo|
|00000eb0| 72 65 0d 0a 79 6f 75 20 | 73 77 69 74 63 68 20 69 |re..you |switch i|
|00000ec0| 6e 2e 20 20 41 6e 64 20 | 69 66 20 79 6f 75 20 73 |n. And |if you s|
|00000ed0| 77 69 74 63 68 20 74 6f | 20 61 6e 20 69 6e 76 61 |witch to| an inva|
|00000ee0| 6c 69 64 20 74 68 72 65 | 61 64 20 6f 72 20 6f 6e |lid thre|ad or on|
|00000ef0| 65 20 77 69 74 68 20 61 | 0d 0a 63 6f 72 72 75 70 |e with a|..corrup|
|00000f00| 74 65 64 20 73 74 61 63 | 6b 2c 20 3c 21 2d 2d 20 |ted stac|k, <!-- |
|00000f10| 4d 41 54 48 0a 20 24 6d | 70 74 68 64 5c 5f 73 77 |MATH. $m|pthd\_sw|
|00000f20| 69 74 63 68 28 29 24 0a | 20 2d 2d 3e 0a 3c 49 3e |itch()$.| -->.<I>|
|00000f30| 6d 70 74 68 64 3c 2f 49 | 3e 3c 49 4d 47 0a 20 53 |mpthd</I|><IMG. S|
|00000f40| 54 59 4c 45 3d 22 68 65 | 69 67 68 74 3a 20 32 35 |TYLE="he|ight: 25|
|00000f50| 2e 33 39 65 78 3b 20 76 | 65 72 74 69 63 61 6c 2d |.39ex; v|ertical-|
|00000f60| 61 6c 69 67 6e 3a 20 31 | 35 31 2e 34 30 65 78 3b |align: 1|51.40ex;|
|00000f70| 20 22 20 53 52 43 3d 22 | 69 6d 67 34 2e 70 6e 67 | " SRC="|img4.png|
|00000f80| 22 0a 20 41 4c 54 3d 22 | 24 5c 5f 73 77 69 74 63 |". ALT="|$\_switc|
|00000f90| 68 24 22 3e 28 29 20 72 | 65 74 75 72 6e 73 20 74 |h$">() r|eturns t|
|00000fa0| 6f 20 79 6f 75 20 74 65 | 6c 6c 69 6e 67 20 79 6f |o you te|lling yo|
|00000fb0| 75 20 74 68 61 74 20 69 | 74 0d 0a 63 61 6d 65 20 |u that i|t..came |
|00000fc0| 66 72 6f 6d 20 3c 45 4d | 3e 79 6f 75 3c 2f 45 4d |from <EM|>you</EM|
|00000fd0| 3e 20 28 6e 6f 74 20 73 | 6f 6d 65 20 6f 74 68 65 |> (not s|ome othe|
|00000fe0| 72 20 74 68 72 65 61 64 | 29 2c 20 77 68 69 63 68 |r thread|), which|
|00000ff0| 20 79 6f 75 20 6d 61 79 | 20 69 6e 74 65 72 70 72 | you may| interpr|
|00001000| 65 74 0d 0a 61 73 20 61 | 6e 20 65 72 72 6f 72 2e |et..as a|n error.|
|00001010| 0a 0a 3c 50 3e 0a 54 68 | 65 20 3c 21 2d 2d 20 4d |..<P>.Th|e <!-- M|
|00001020| 41 54 48 0a 20 24 6d 70 | 74 68 64 5c 5f 73 77 69 |ATH. $mp|thd\_swi|
|00001030| 74 63 68 28 29 24 0a 20 | 2d 2d 3e 0a 3c 49 3e 6d |tch()$. |-->.<I>m|
|00001040| 70 74 68 64 3c 2f 49 3e | 3c 49 4d 47 0a 20 53 54 |pthd</I>|<IMG. ST|
|00001050| 59 4c 45 3d 22 68 65 69 | 67 68 74 3a 20 32 35 2e |YLE="hei|ght: 25.|
|00001060| 33 39 65 78 3b 20 76 65 | 72 74 69 63 61 6c 2d 61 |39ex; ve|rtical-a|
|00001070| 6c 69 67 6e 3a 20 31 35 | 31 2e 34 30 65 78 3b 20 |lign: 15|1.40ex; |
|00001080| 22 20 53 52 43 3d 22 69 | 6d 67 34 2e 70 6e 67 22 |" SRC="i|mg4.png"|
|00001090| 0a 20 41 4c 54 3d 22 24 | 5c 5f 73 77 69 74 63 68 |. ALT="$|\_switch|
|000010a0| 24 22 3e 28 29 20 69 6e | 74 65 72 66 61 63 65 20 |$">() in|terface |
|000010b0| 69 73 20 61 6c 73 6f 20 | 70 6f 72 74 61 62 6c 65 |is also |portable|
|000010c0| 2e 20 20 49 6e 20 6d 61 | 6e 79 20 63 61 73 65 73 |. In ma|ny cases|
|000010d0| 20 69 74 20 63 61 6e 0d | 0a 62 65 20 64 69 72 65 | it can.|.be dire|
|000010e0| 63 74 6c 79 20 69 6d 70 | 6c 65 6d 65 6e 74 65 64 |ctly imp|lemented|
|000010f0| 20 77 69 74 68 20 60 60 | 43 27 27 27 73 20 73 74 | with ``|C'''s st|
|00001100| 61 6e 64 61 72 64 20 3c | 49 3e 73 65 74 6a 6d 70 |andard <|I>setjmp|
|00001110| 3c 2f 49 3e 28 29 20 61 | 6e 64 20 3c 49 3e 6c 6f |</I>() a|nd <I>lo|
|00001120| 6e 67 6a 6d 70 3c 2f 49 | 3e 28 29 0d 0a 66 75 6e |ngjmp</I|>()..fun|
|00001130| 63 74 69 6f 6e 73 2e 20 | 20 49 6e 20 6f 74 68 65 |ctions. | In othe|
|00001140| 72 20 6c 61 6e 67 75 61 | 67 65 73 2c 20 74 68 65 |r langua|ges, the|
|00001150| 20 66 75 6e 63 74 69 6f | 6e 20 69 73 20 71 75 69 | functio|n is qui|
|00001160| 63 6b 6c 79 20 63 6f 64 | 65 64 20 69 6e 0d 0a 61 |ckly cod|ed in..a|
|00001170| 73 73 65 6d 62 6c 79 20 | 61 6e 64 20 60 60 6c 69 |ssembly |and ``li|
|00001180| 6e 6b 65 64 20 69 6e 2e | 27 27 20 20 4d 6f 73 74 |nked in.|'' Most|
|00001190| 20 65 76 65 72 79 20 73 | 74 61 63 6b 20 62 61 73 | every s|tack bas|
|000011a0| 65 64 2d 6d 61 63 68 69 | 6e 65 73 20 63 61 6e 0d |ed-machi|nes can.|
|000011b0| 0a 73 75 70 70 6f 72 74 | 20 69 74 20 28 73 65 65 |.support| it (see|
|000011c0| 20 69 6e 74 65 72 6e 61 | 6c 20 72 65 70 72 65 73 | interna|l repres|
|000011d0| 65 6e 74 61 74 69 6f 6e | 29 2e 0a 0a 3c 50 3e 0a |entation|)...<P>.|
|000011e0| 0a 3c 44 49 56 20 63 6c | 61 73 73 3d 22 43 45 4e |.<DIV cl|ass="CEN|
|000011f0| 54 45 52 22 3e 3c 41 20 | 49 44 3d 22 31 30 38 22 |TER"><A |ID="108"|
|00001200| 3e 3c 2f 41 3e 0a 3c 54 | 41 42 4c 45 3e 0a 3c 43 |></A>.<T|ABLE>.<C|
|00001210| 41 50 54 49 4f 4e 20 63 | 6c 61 73 73 3d 22 42 4f |APTION c|lass="BO|
|00001220| 54 54 4f 4d 22 3e 3c 53 | 54 52 4f 4e 47 3e 46 69 |TTOM"><S|TRONG>Fi|
|00001230| 67 75 72 65 3a 3c 2f 53 | 54 52 4f 4e 47 3e 0a 4d |gure:</S|TRONG>.M|
|00001240| 50 54 48 44 3a 20 20 54 | 68 72 65 61 64 20 44 61 |PTHD: T|hread Da|
|00001250| 74 61 74 79 70 65 20 49 | 6e 74 65 72 6e 61 6c 73 |tatype I|nternals|
|00001260| 3c 2f 43 41 50 54 49 4f | 4e 3e 0a 3c 54 52 3e 3c |</CAPTIO|N>.<TR><|
|00001270| 54 44 3e 3c 49 4d 47 0a | 20 53 54 59 4c 45 3d 22 |TD><IMG.| STYLE="|
|00001280| 68 65 69 67 68 74 3a 20 | 33 31 34 2e 30 30 65 78 |height: |314.00ex|
|00001290| 3b 20 22 20 53 52 43 3d | 22 69 6d 67 36 2e 70 6e |; " SRC=|"img6.pn|
|000012a0| 67 22 0a 20 41 4c 54 3d | 22 5c 62 65 67 69 6e 7b |g". ALT=|"\begin{|
|000012b0| 66 69 67 75 72 65 7d 5c | 70 61 72 0a 5c 62 65 67 |figure}\|par.\beg|
|000012c0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 53 65 6d |in{verba|tim}.Sem|
|000012d0| 61 70 68 6f 72 65 20 28 | 74 6f 20 63 6f 6e 74 72 |aphore (|to contr|
|000012e0| 6f 6c 20 6d 75 6c 74 69 | 70 72 6f 63 65 73 73 6f |ol multi|processo|
|000012f0| 72 2e 2e 2e 0a 2e 2e 2e | 0a 6a 6d 70 5f 62 75 66 |r.......|.jmp_buf|
|00001300| 20 28 66 6f 72 20 73 61 | 76 69 6e 67 20 74 68 65 | (for sa|ving the|
|00001310| 20 74 68 72 65 61 64 27 | 73 20 65 78 65 63 75 74 | thread'|s execut|
|00001320| 69 6f 6e 20 73 74 61 74 | 65 29 5c 65 6e 64 7b 76 |ion stat|e)\end{v|
|00001330| 65 72 62 61 74 69 6d 7d | 0a 5c 65 6e 64 7b 66 69 |erbatim}|.\end{fi|
|00001340| 67 75 72 65 7d 22 3e 3c | 2f 54 44 3e 3c 2f 54 52 |gure}"><|/TD></TR|
|00001350| 3e 0a 3c 2f 54 41 42 4c | 45 3e 0a 3c 2f 44 49 56 |>.</TABL|E>.</DIV|
|00001360| 3e 0a 0a 3c 50 3e 0a 57 | 69 74 68 20 61 20 66 65 |>..<P>.W|ith a fe|
|00001370| 77 20 61 64 64 69 74 69 | 6f 6e 61 6c 20 73 75 70 |w additi|onal sup|
|00001380| 70 6f 72 74 20 66 75 6e | 63 74 69 6f 6e 73 2c 20 |port fun|ctions, |
|00001390| 74 68 72 65 61 64 73 20 | 63 61 6e 20 62 65 20 65 |threads |can be e|
|000013a0| 61 73 69 6c 79 20 63 72 | 65 61 74 65 64 0d 0a 61 |asily cr|eated..a|
|000013b0| 6e 64 20 64 65 73 74 72 | 6f 79 65 64 20 28 73 65 |nd destr|oyed (se|
|000013c0| 65 20 4d 41 4e 20 70 61 | 67 65 20 66 6f 72 20 65 |e MAN pa|ge for e|
|000013d0| 78 61 63 74 20 64 65 74 | 61 69 6c 73 29 2e 0a 0a |xact det|ails)...|
|000013e0| 3c 50 3e 0a 4e 6f 74 69 | 63 65 20 74 68 61 74 20 |<P>.Noti|ce that |
|000013f0| 74 68 65 20 69 6e 69 74 | 69 61 6c 69 7a 61 74 69 |the init|ializati|
|00001400| 6f 6e 20 66 75 6e 63 74 | 69 6f 6e 20 72 65 71 75 |on funct|ion requ|
|00001410| 69 72 65 73 20 73 65 76 | 65 72 61 6c 20 28 74 68 |ires sev|eral (th|
|00001420| 72 65 65 29 0d 0a 61 72 | 67 75 6d 65 6e 74 73 3a |ree)..ar|guments:|
|00001430| 20 74 68 65 20 6d 65 6d | 6f 72 79 20 62 75 66 66 | the mem|ory buff|
|00001440| 65 72 20 75 73 65 64 20 | 74 6f 20 73 74 6f 72 65 |er used |to store|
|00001450| 20 74 68 65 20 74 68 72 | 65 61 64 2c 20 74 68 65 | the thr|ead, the|
|00001460| 20 73 69 7a 65 20 6f 66 | 0d 0a 74 68 65 20 62 75 | size of|..the bu|
|00001470| 66 66 65 72 2c 20 61 6e | 64 20 74 68 65 20 66 75 |ffer, an|d the fu|
|00001480| 6e 63 74 69 6f 6e 20 74 | 6f 20 65 78 65 63 75 74 |nction t|o execut|
|00001490| 65 2e 20 20 41 6c 6c 20 | 74 68 69 73 20 69 73 20 |e. All |this is |
|000014a0| 61 77 6b 77 61 72 64 20 | 74 6f 0d 0a 73 70 65 63 |awkward |to..spec|
|000014b0| 69 66 79 20 77 68 65 6e | 20 77 65 20 73 65 74 20 |ify when| we set |
|000014c0| 75 70 20 61 20 74 68 72 | 65 61 64 2c 20 73 6f 20 |up a thr|ead, so |
|000014d0| 73 75 70 70 6f 73 65 20 | 77 65 20 73 74 6f 72 65 |suppose |we store|
|000014e0| 20 61 20 64 65 66 61 75 | 6c 74 20 73 69 7a 65 0d | a defau|lt size.|
|000014f0| 0a 69 6e 20 73 6f 6d 65 | 20 67 6c 6f 62 61 6c 20 |.in some| global |
|00001500| 76 61 72 69 61 62 6c 65 | 2e 20 20 42 75 74 2c 20 |variable|. But, |
|00001510| 72 65 6d 65 6d 62 65 72 | 2c 20 77 65 27 72 65 20 |remember|, we're |
|00001520| 69 6e 20 61 20 63 6f 6e | 63 75 72 72 65 6e 74 0d |in a con|current.|
|00001530| 0a 65 6e 76 69 72 6f 6e | 6d 65 6e 74 3a 20 64 69 |.environ|ment: di|
|00001540| 66 66 65 72 65 6e 74 20 | 74 61 73 6b 73 20 6d 61 |fferent |tasks ma|
|00001550| 79 20 63 68 61 6e 67 65 | 20 74 68 65 20 64 65 66 |y change| the def|
|00001560| 61 75 6c 74 20 76 61 6c | 75 65 2c 20 61 6e 64 0d |ault val|ue, and.|
|00001570| 0a 64 69 66 66 65 72 65 | 6e 74 20 74 61 73 6b 73 |.differe|nt tasks|
|00001580| 20 6d 61 79 20 77 61 6e | 74 20 64 69 66 66 65 72 | may wan|t differ|
|00001590| 65 6e 74 20 64 65 66 61 | 75 6c 74 73 2e 20 20 54 |ent defa|ults. T|
|000015a0| 68 65 72 65 66 6f 72 65 | 2c 20 74 68 65 20 74 68 |herefore|, the th|
|000015b0| 72 65 61 64 0d 0a 6d 61 | 69 6e 74 61 69 6e 73 20 |read..ma|intains |
|000015c0| 61 20 68 65 61 70 2c 20 | 70 72 69 76 61 74 65 20 |a heap, |private |
|000015d0| 74 6f 20 74 68 61 74 20 | 74 61 73 6b 2e 20 20 49 |to that |task. I|
|000015e0| 6e 73 74 65 61 64 2c 20 | 77 65 20 63 61 6e 20 73 |nstead, |we can s|
|000015f0| 65 74 20 75 70 20 61 0d | 0a 67 6c 6f 62 61 6c 20 |et up a.|.global |
|00001600| 63 6f 6e 73 74 61 6e 74 | 2c 20 61 6e 20 3c 45 4d |constant|, an <EM|
|00001610| 3e 6f 66 66 73 65 74 3c | 2f 45 4d 3e 20 69 6e 74 |>offset<|/EM> int|
|00001620| 6f 20 74 68 65 20 3c 45 | 4d 3e 63 75 72 72 65 6e |o the <E|M>curren|
|00001630| 74 20 74 68 72 65 61 64 | 27 73 3c 2f 45 4d 3e 0d |t thread|'s</EM>.|
|00001640| 0a 68 65 61 70 2c 20 63 | 6f 6e 74 61 69 6e 69 6e |.heap, c|ontainin|
|00001650| 67 20 6f 75 72 20 64 65 | 66 61 75 6c 74 20 62 75 |g our de|fault bu|
|00001660| 66 66 65 72 20 73 69 7a | 65 2e 20 20 54 68 61 74 |ffer siz|e. That|
|00001670| 20 77 61 79 2c 20 65 61 | 63 68 20 74 61 73 6b 20 | way, ea|ch task |
|00001680| 68 61 73 0d 0a 69 74 73 | 20 6f 77 6e 20 64 65 66 |has..its| own def|
|00001690| 61 75 6c 74 73 2c 20 62 | 75 74 20 72 65 66 65 72 |aults, b|ut refer|
|000016a0| 20 74 6f 20 74 68 65 6d | 20 77 69 74 68 20 74 68 | to them| with th|
|000016b0| 65 20 3c 45 4d 3e 73 61 | 6d 65 3c 2f 45 4d 3e 20 |e <EM>sa|me</EM> |
|000016c0| 76 61 72 69 61 62 6c 65 | 0d 0a 6e 61 6d 65 2e 20 |variable|..name. |
|000016d0| 20 4d 50 54 48 44 20 61 | 75 74 6f 6d 61 74 69 63 | MPTHD a|utomatic|
|000016e0| 61 6c 6c 79 20 63 6f 70 | 69 65 73 20 74 68 65 20 |ally cop|ies the |
|000016f0| 70 61 72 65 6e 74 27 73 | 20 68 65 61 70 20 77 68 |parent's| heap wh|
|00001700| 65 6e 20 69 6e 69 74 69 | 61 6c 69 7a 69 6e 67 0d |en initi|alizing.|
|00001710| 0a 61 20 6e 65 77 20 74 | 68 72 65 61 64 2c 20 73 |.a new t|hread, s|
|00001720| 6f 20 64 65 66 61 75 6c | 74 73 20 61 72 65 20 69 |o defaul|ts are i|
|00001730| 6e 68 65 72 69 74 65 64 | 2e 20 20 54 68 69 73 20 |nherited|. This |
|00001740| 73 69 6d 70 6c 65 20 66 | 65 61 74 75 72 65 20 63 |simple f|eature c|
|00001750| 61 6e 0d 0a 61 6c 73 6f | 20 62 65 20 75 73 65 64 |an..also| be used|
|00001760| 20 66 6f 72 20 70 61 73 | 73 69 6e 67 20 61 72 67 | for pas|sing arg|
|00001770| 75 6d 65 6e 74 73 20 66 | 72 6f 6d 20 74 68 65 20 |uments f|rom the |
|00001780| 70 61 72 65 6e 74 20 74 | 6f 20 74 68 65 20 63 68 |parent t|o the ch|
|00001790| 69 6c 64 0d 0a 74 68 72 | 65 61 64 2e 0a 0a 3c 50 |ild..thr|ead...<P|
|000017a0| 3e 0a 53 6f 20 66 61 72 | 20 73 6f 20 67 6f 6f 64 |>.So far| so good|
|000017b0| 2e 20 20 4e 6f 77 20 73 | 75 70 70 6f 73 65 20 77 |. Now s|uppose w|
|000017c0| 65 20 61 6c 73 6f 20 64 | 6f 6e 27 74 20 77 61 6e |e also d|on't wan|
|000017d0| 74 20 74 6f 20 73 70 65 | 63 69 66 79 20 61 20 74 |t to spe|cify a t|
|000017e0| 68 65 0d 0a 62 75 66 66 | 65 72 20 73 74 6f 72 69 |he..buff|er stori|
|000017f0| 6e 67 20 61 20 74 68 72 | 65 61 64 20 26 6e 64 61 |ng a thr|ead &nda|
|00001800| 73 68 3b 20 73 75 70 70 | 6f 73 65 2c 20 69 6e 73 |sh; supp|ose, ins|
|00001810| 74 65 61 64 2c 20 4d 50 | 54 48 44 20 63 61 6c 6c |tead, MP|THD call|
|00001820| 65 64 20 6d 61 6c 6c 6f | 63 20 74 6f 0d 0a 64 79 |ed mallo|c to..dy|
|00001830| 6e 61 6d 69 63 61 6c 6c | 79 20 61 6c 6c 6f 63 61 |namicall|y alloca|
|00001840| 74 65 20 73 74 6f 72 61 | 67 65 20 66 6f 72 20 75 |te stora|ge for u|
|00001850| 73 2e 20 20 41 68 68 2c | 20 62 75 74 20 73 74 6f |s. Ahh,| but sto|
|00001860| 72 61 67 65 20 69 73 20 | 61 20 3c 45 4d 3e 0d 0a |rage is |a <EM>..|
|00001870| 72 65 73 6f 75 72 63 65 | 3c 2f 45 4d 3e 2e 20 20 |resource|</EM>. |
|00001880| 4e 6f 74 20 61 6c 6c 20 | 6c 61 6e 67 75 61 67 65 |Not all |language|
|00001890| 73 20 68 61 76 65 20 74 | 68 69 73 20 72 65 73 6f |s have t|his reso|
|000018a0| 75 72 63 65 20 28 6c 69 | 6d 69 74 69 6e 67 0d 0a |urce (li|miting..|
|000018b0| 70 6f 72 74 61 62 69 6c | 69 74 79 29 2e 20 20 4d |portabil|ity). M|
|000018c0| 6f 72 65 20 69 6d 70 6f | 72 74 61 6e 74 6c 79 2c |ore impo|rtantly,|
|000018d0| 20 64 79 6e 61 6d 69 63 | 20 6d 65 6d 6f 72 79 20 | dynamic| memory |
|000018e0| 61 6c 6c 6f 63 61 74 69 | 6f 6e 20 73 6f 6d 65 74 |allocati|on somet|
|000018f0| 69 6d 65 73 0d 0a 74 61 | 6b 65 73 20 74 69 6d 65 |imes..ta|kes time|
|00001900| 20 26 6e 64 61 73 68 3b | 20 69 74 20 6d 75 73 74 | &ndash;| it must|
|00001910| 20 62 65 20 69 6e 74 65 | 72 72 75 70 74 61 62 6c | be inte|rruptabl|
|00001920| 65 2e 20 20 41 20 68 69 | 67 68 2d 6c 65 76 65 6c |e. A hi|gh-level|
|00001930| 20 73 63 68 65 64 75 6c | 65 72 20 6d 61 79 0d 0a | schedul|er may..|
|00001940| 73 77 69 74 63 68 20 69 | 6e 74 6f 20 61 6e 6f 74 |switch i|nto anot|
|00001950| 68 65 72 20 74 68 72 65 | 61 64 20 77 68 69 63 68 |her thre|ad which|
|00001960| 20 61 6c 6c 6f 63 61 74 | 65 73 20 6d 65 6d 6f 72 | allocat|es memor|
|00001970| 79 20 77 68 69 6c 65 20 | 6f 75 72 20 74 68 72 65 |y while |our thre|
|00001980| 61 64 0d 0a 69 73 20 64 | 6f 69 6e 67 20 74 68 65 |ad..is d|oing the|
|00001990| 20 73 61 6d 65 21 20 20 | 42 65 63 61 75 73 65 20 | same! |Because |
|000019a0| 6d 65 6d 6f 72 79 20 61 | 6c 6c 6f 63 61 74 69 6f |memory a|llocatio|
|000019b0| 6e 20 69 73 20 61 20 72 | 65 73 6f 75 72 63 65 2c |n is a r|esource,|
|000019c0| 20 74 68 69 73 0d 0a 66 | 65 61 74 75 72 65 20 77 | this..f|eature w|
|000019d0| 69 6c 6c 20 68 61 76 65 | 20 74 6f 20 77 61 69 74 |ill have| to wait|
|000019e0| 20 66 6f 72 20 68 69 67 | 68 65 72 20 6c 65 76 65 | for hig|her leve|
|000019f0| 6c 73 2e 0a 0a 3c 50 3e | 0a 49 6e 20 73 68 6f 72 |ls...<P>|.In shor|
|00001a00| 74 2c 20 74 68 65 20 4d | 50 54 48 44 20 63 6c 75 |t, the M|PTHD clu|
|00001a10| 73 74 65 72 2c 20 77 69 | 74 68 20 74 68 65 20 3c |ster, wi|th the <|
|00001a20| 21 2d 2d 20 4d 41 54 48 | 0a 20 24 6d 70 74 68 64 |!-- MATH|. $mpthd|
|00001a30| 5c 5f 73 77 69 74 63 68 | 28 29 24 0a 20 2d 2d 3e |\_switch|()$. -->|
|00001a40| 0a 3c 49 3e 6d 70 74 68 | 64 3c 2f 49 3e 3c 49 4d |.<I>mpth|d</I><IM|
|00001a50| 47 0a 20 53 54 59 4c 45 | 3d 22 68 65 69 67 68 74 |G. STYLE|="height|
|00001a60| 3a 20 32 35 2e 33 39 65 | 78 3b 20 76 65 72 74 69 |: 25.39e|x; verti|
|00001a70| 63 61 6c 2d 61 6c 69 67 | 6e 3a 20 31 35 31 2e 34 |cal-alig|n: 151.4|
|00001a80| 30 65 78 3b 20 22 20 53 | 52 43 3d 22 69 6d 67 34 |0ex; " S|RC="img4|
|00001a90| 2e 70 6e 67 22 0a 20 41 | 4c 54 3d 22 24 5c 5f 73 |.png". A|LT="$\_s|
|00001aa0| 77 69 74 63 68 24 22 3e | 28 29 20 66 75 6e 63 74 |witch$">|() funct|
|00001ab0| 69 6f 6e 2c 0d 0a 69 73 | 20 61 20 73 69 6d 70 6c |ion,..is| a simpl|
|00001ac0| 65 20 61 6e 64 20 70 6f | 72 74 61 62 6c 65 20 77 |e and po|rtable w|
|00001ad0| 61 79 20 74 6f 20 64 6f | 20 63 6f 6e 74 65 78 74 |ay to do| context|
|00001ae0| 20 73 77 69 74 63 68 69 | 6e 67 2e 20 20 54 68 65 | switchi|ng. The|
|00001af0| 20 70 61 63 6b 61 67 65 | 0d 0a 70 72 6f 76 69 64 | package|..provid|
|00001b00| 65 73 20 65 78 61 6d 70 | 6c 65 73 20 6f 66 20 68 |es examp|les of h|
|00001b10| 6f 77 20 69 74 20 63 61 | 6e 20 62 65 20 75 73 65 |ow it ca|n be use|
|00001b20| 64 2c 20 73 75 63 68 20 | 61 73 20 61 20 74 61 6e |d, such |as a tan|
|00001b30| 6b 20 67 61 6d 65 20 69 | 6e 20 77 68 69 63 68 0d |k game i|n which.|
|00001b40| 0a 65 6e 74 72 61 6e 74 | 73 20 73 75 62 6d 69 74 |.entrant|s submit|
|00001b50| 20 60 60 43 27 27 20 70 | 72 6f 67 72 61 6d 73 20 | ``C'' p|rograms |
|00001b60| 74 6f 20 63 6f 6e 74 72 | 6f 6c 20 74 68 65 69 72 |to contr|ol their|
|00001b70| 20 74 61 6e 6b 73 2e 20 | 20 45 61 63 68 0d 0a 60 | tanks. | Each..`|
|00001b80| 60 70 72 6f 67 72 61 6d | 27 27 20 72 75 6e 73 20 |`program|'' runs |
|00001b90| 61 73 20 61 6e 20 69 6e | 64 65 70 65 6e 64 65 6e |as an in|dependen|
|00001ba0| 74 20 74 68 72 65 61 64 | 2c 20 77 69 74 68 20 61 |t thread|, with a|
|00001bb0| 20 60 60 72 65 66 65 72 | 65 65 27 27 20 74 68 72 | ``refer|ee'' thr|
|00001bc0| 65 61 64 0d 0a 73 63 68 | 65 64 75 6c 69 6e 67 20 |ead..sch|eduling |
|00001bd0| 74 68 65 20 62 61 74 74 | 6c 65 21 0a 0a 3c 50 3e |the batt|le!..<P>|
|00001be0| 0a 0a 3c 48 52 3e 0a 0a | 3c 2f 42 4f 44 59 3e 0a |..<HR>..|</BODY>.|
|00001bf0| 3c 2f 48 54 4d 4c 3e 0a | |</HTML>.| |
+--------+-------------------------+-------------------------+--------+--------+