Artifact
26f3937b7d3ba39fa6ae1d065e0e78bdeabbf31e:
Attachment "932527.patch" to
ticket [932527ffff]
added by
dgp
2004-04-26 07:03:37.
0000: 49 6e 64 65 78 3a 20 64 6f 63 2f 54 68 72 65 61 Index: doc/Threa
0010: 64 2e 33 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d d.3.============
0020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0050: 3d 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c 65 =======.RCS file
0060: 3a 20 2f 63 76 73 72 6f 6f 74 2f 74 63 6c 2f 74 : /cvsroot/tcl/t
0070: 63 6c 2f 64 6f 63 2f 54 68 72 65 61 64 2e 33 2c cl/doc/Thread.3,
0080: 76 0a 72 65 74 72 69 65 76 69 6e 67 20 72 65 76 v.retrieving rev
0090: 69 73 69 6f 6e 20 31 2e 31 36 0a 64 69 66 66 20 ision 1.16.diff
00a0: 2d 75 20 2d 72 31 2e 31 36 20 54 68 72 65 61 64 -u -r1.16 Thread
00b0: 2e 33 0a 2d 2d 2d 20 64 6f 63 2f 54 68 72 65 61 .3.--- doc/Threa
00c0: 64 2e 33 09 31 36 20 41 70 72 20 32 30 30 34 20 d.3.16 Apr 2004
00d0: 32 30 3a 34 34 3a 31 38 20 2d 30 30 30 30 09 31 20:44:18 -0000.1
00e0: 2e 31 36 0a 2b 2b 2b 20 64 6f 63 2f 54 68 72 65 .16.+++ doc/Thre
00f0: 61 64 2e 33 09 32 36 20 41 70 72 20 32 30 30 34 ad.3.26 Apr 2004
0100: 20 30 30 3a 30 31 3a 33 33 20 2d 30 30 30 30 0a 00:01:33 -0000.
0110: 40 40 20 2d 39 32 2c 37 20 2b 39 32 2c 36 20 40 @@ -92,7 +92,6 @
0120: 40 0a 20 72 65 6c 65 61 73 65 73 2c 20 61 20 73 @. releases, a s
0130: 69 6e 67 6c 65 20 74 68 72 65 61 64 20 63 61 6e ingle thread can
0140: 20 73 61 66 65 6c 79 20 63 72 65 61 74 65 20 61 safely create a
0150: 6e 64 20 75 73 65 20 6d 75 6c 74 69 70 6c 65 0a nd use multiple.
0160: 20 69 6e 74 65 72 70 72 65 74 65 72 73 2e 29 0a interpreters.).
0170: 20 2e 50 50 0a 2d 2e 56 53 20 38 2e 33 2e 31 0a .PP.-.VS 8.3.1.
0180: 20 54 63 6c 20 64 6f 65 73 20 70 72 6f 76 69 64 Tcl does provid
0190: 65 20 5c 66 42 54 63 6c 5f 43 72 65 61 74 65 54 e \fBTcl_CreateT
01a0: 68 72 65 61 64 5c 66 52 20 66 6f 72 20 63 72 65 hread\fR for cre
01b0: 61 74 69 6e 67 20 74 68 72 65 61 64 73 2e 20 54 ating threads. T
01c0: 68 65 0a 20 63 61 6c 6c 65 72 20 63 61 6e 20 64 he. caller can d
01d0: 65 74 65 72 6d 69 6e 65 20 74 68 65 20 73 69 7a etermine the siz
01e0: 65 20 6f 66 20 74 68 65 20 73 74 61 63 6b 20 67 e of the stack g
01f0: 69 76 65 6e 20 74 6f 20 74 68 65 20 6e 65 77 20 iven to the new
0200: 74 68 72 65 61 64 20 61 6e 64 0a 20 6d 6f 64 69 thread and. modi
0210: 66 79 20 74 68 65 20 62 65 68 61 76 69 6f 75 72 fy the behaviour
0220: 20 74 68 72 6f 75 67 68 20 74 68 65 20 73 75 70 through the sup
0230: 70 6c 69 65 64 20 5c 66 49 66 6c 61 67 73 5c 66 plied \fIflags\f
0240: 52 2e 20 54 68 65 20 76 61 6c 75 65 0a 40 40 20 R. The value.@@
0250: 2d 31 31 30 2c 31 34 20 2b 31 30 39 2c 31 32 20 -110,14 +109,12
0260: 40 40 0a 20 73 70 65 63 69 66 69 65 64 20 76 61 @@. specified va
0270: 6c 75 65 20 66 6f 72 20 74 68 65 20 73 74 61 63 lue for the stac
0280: 6b 73 69 7a 65 20 69 73 20 69 67 6e 6f 72 65 64 ksize is ignored
0290: 20 6f 6e 20 74 68 65 73 65 20 73 79 73 74 65 6d on these system
02a0: 73 2e 0a 20 57 69 6e 64 6f 77 73 20 63 75 72 72 s.. Windows curr
02b0: 65 6e 74 6c 79 20 64 6f 65 73 20 6e 6f 74 20 73 ently does not s
02c0: 75 70 70 6f 72 74 20 6a 6f 69 6e 61 62 6c 65 20 upport joinable
02d0: 74 68 72 65 61 64 73 2e 20 54 68 69 73 0a 20 66 threads. This. f
02e0: 6c 61 67 20 76 61 6c 75 65 20 69 73 20 74 68 65 lag value is the
02f0: 72 65 66 6f 72 65 20 69 67 6e 6f 72 65 64 20 6f refore ignored o
0300: 6e 20 74 68 69 73 20 70 6c 61 74 66 6f 72 6d 2e n this platform.
0310: 0a 2d 2e 56 45 0a 20 2e 50 50 0a 20 54 63 6c 20 .-.VE. .PP. Tcl
0320: 64 6f 65 73 20 70 72 6f 76 69 64 65 20 5c 66 42 does provide \fB
0330: 54 63 6c 5f 45 78 69 74 54 68 72 65 61 64 5c 66 Tcl_ExitThread\f
0340: 52 20 61 6e 64 20 5c 66 42 54 63 6c 5f 46 69 6e R and \fBTcl_Fin
0350: 61 6c 69 7a 65 54 68 72 65 61 64 5c 66 52 0a 20 alizeThread\fR.
0360: 66 6f 72 20 74 65 72 6d 69 6e 61 74 69 6e 67 20 for terminating
0370: 74 68 72 65 61 64 73 20 61 6e 64 20 69 6e 76 6f threads and invo
0380: 6b 69 6e 67 20 6f 70 74 69 6f 6e 61 6c 20 70 65 king optional pe
0390: 72 2d 74 68 72 65 61 64 20 65 78 69 74 0a 20 68 r-thread exit. h
03a0: 61 6e 64 6c 65 72 73 2e 20 20 53 65 65 20 74 68 andlers. See th
03b0: 65 20 5c 66 42 54 63 6c 5f 45 78 69 74 5c 66 52 e \fBTcl_Exit\fR
03c0: 20 70 61 67 65 20 66 6f 72 20 6d 6f 72 65 20 69 page for more i
03d0: 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 74 68 nformation on th
03e0: 65 73 65 0a 20 70 72 6f 63 65 64 75 72 65 73 2e ese. procedures.
03f0: 0a 20 2e 50 50 0a 2d 2e 56 53 0a 20 54 68 65 20 . .PP.-.VS. The
0400: 5c 66 42 54 63 6c 5f 4a 6f 69 6e 54 68 72 65 61 \fBTcl_JoinThrea
0410: 64 5c 66 52 20 66 75 6e 63 74 69 6f 6e 20 69 73 d\fR function is
0420: 20 70 72 6f 76 69 64 65 64 20 74 6f 20 61 6c 6c provided to all
0430: 6f 77 20 74 68 72 65 61 64 73 20 74 6f 20 77 61 ow threads to wa
0440: 69 74 0a 20 75 70 6f 6e 20 74 68 65 20 65 78 69 it. upon the exi
0450: 74 20 6f 66 20 61 6e 6f 74 68 65 72 20 74 68 72 t of another thr
0460: 65 61 64 2c 20 77 68 69 63 68 20 6d 75 73 74 20 ead, which must
0470: 68 61 76 65 20 62 65 65 6e 20 6d 61 72 6b 65 64 have been marked
0480: 20 61 73 0a 20 6a 6f 69 6e 61 62 6c 65 20 74 68 as. joinable th
0490: 72 6f 75 67 68 20 75 73 61 67 65 20 6f 66 20 74 rough usage of t
04a0: 68 65 20 5c 66 42 54 43 4c 5f 54 48 52 45 41 44 he \fBTCL_THREAD
04b0: 5f 4a 4f 49 4e 41 42 4c 45 5c 66 52 2d 66 6c 61 _JOINABLE\fR-fla
04c0: 67 20 64 75 72 69 6e 67 0a 40 40 20 2d 31 32 39 g during.@@ -129
04d0: 2c 33 30 20 2b 31 32 36 2c 32 37 20 40 40 0a 20 ,30 +126,27 @@.
04e0: 6e 65 63 65 73 73 61 72 79 20 69 6e 66 6f 72 6d necessary inform
04f0: 61 74 69 6f 6e 20 75 6e 74 69 6c 20 61 66 74 65 ation until afte
0500: 72 20 74 68 65 20 63 61 6c 6c 20 74 6f 20 5c 66 r the call to \f
0510: 42 54 63 6c 5f 4a 6f 69 6e 54 68 72 65 61 64 5c BTcl_JoinThread\
0520: 66 52 2e 0a 20 54 68 69 73 20 6d 65 61 6e 73 20 fR.. This means
0530: 74 68 61 74 20 6e 6f 74 20 63 61 6c 6c 69 6e 67 that not calling
0540: 20 5c 66 42 54 63 6c 5f 4a 6f 69 6e 54 68 72 65 \fBTcl_JoinThre
0550: 61 64 5c 66 52 20 66 6f 72 20 61 20 6a 6f 69 6e ad\fR for a join
0560: 61 62 6c 65 20 74 68 72 65 61 64 0a 20 77 69 6c able thread. wil
0570: 6c 20 63 61 75 73 65 20 61 20 6d 65 6d 6f 72 79 l cause a memory
0580: 20 6c 65 61 6b 2e 0a 2d 2e 56 45 0a 20 2e 50 50 leak..-.VE. .PP
0590: 0a 20 54 63 6c 20 70 72 6f 76 69 64 65 73 20 5c . Tcl provides \
05a0: 66 42 54 63 6c 5f 54 68 72 65 61 64 51 75 65 75 fBTcl_ThreadQueu
05b0: 65 45 76 65 6e 74 5c 66 52 20 61 6e 64 20 5c 66 eEvent\fR and \f
05c0: 42 54 63 6c 5f 54 68 72 65 61 64 41 6c 65 72 74 BTcl_ThreadAlert
05d0: 5c 66 52 0a 20 66 6f 72 20 68 61 6e 64 6c 69 6e \fR. for handlin
05e0: 67 20 65 76 65 6e 74 20 71 75 65 75 65 69 6e 67 g event queueing
05f0: 20 69 6e 20 6d 75 6c 74 69 74 68 72 65 61 64 65 in multithreade
0600: 64 20 61 70 70 6c 69 63 61 74 69 6f 6e 73 2e 20 d applications.
0610: 20 53 65 65 0a 20 74 68 65 20 5c 66 42 4e 6f 74 See. the \fBNot
0620: 69 66 69 65 72 5c 66 52 20 6d 61 6e 75 61 6c 20 ifier\fR manual
0630: 70 61 67 65 20 66 6f 72 20 6d 6f 72 65 20 69 6e page for more in
0640: 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 74 68 65 formation on the
0650: 73 65 20 70 72 6f 63 65 64 75 72 65 73 2e 0a 20 se procedures..
0660: 2e 50 50 0a 2d 49 6e 20 74 68 69 73 20 72 65 6c .PP.-In this rel
0670: 65 61 73 65 2c 20 74 68 65 20 54 63 6c 20 6c 61 ease, the Tcl la
0680: 6e 67 75 61 67 65 20 69 74 73 65 6c 66 20 70 72 nguage itself pr
0690: 6f 76 69 64 65 73 20 6e 6f 20 73 75 70 70 6f 72 ovides no suppor
06a0: 74 20 66 6f 72 0a 2d 63 72 65 61 74 69 6e 67 20 t for.-creating
06b0: 6d 75 6c 74 69 74 68 72 65 61 64 65 64 20 73 63 multithreaded sc
06c0: 72 69 70 74 73 20 28 66 6f 72 20 65 78 61 6d 70 ripts (for examp
06d0: 6c 65 2c 20 73 63 72 69 70 74 73 20 74 68 61 74 le, scripts that
06e0: 20 63 6f 75 6c 64 20 73 70 61 77 6e 0a 2d 61 20 could spawn.-a
06f0: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 20 Tcl interpreter
0700: 69 6e 20 61 20 73 65 70 61 72 61 74 65 20 74 68 in a separate th
0710: 72 65 61 64 29 2e 20 20 49 66 20 79 6f 75 20 6e read). If you n
0720: 65 65 64 20 74 6f 20 61 64 64 20 74 68 69 73 0a eed to add this.
0730: 2d 66 65 61 74 75 72 65 20 61 74 20 74 68 69 73 -feature at this
0740: 20 74 69 6d 65 2c 20 73 65 65 20 74 68 65 20 5c time, see the \
0750: 66 49 74 63 6c 54 68 72 65 61 64 54 65 73 74 2e fItclThreadTest.
0760: 63 5c 66 52 0a 2d 66 69 6c 65 20 69 6e 20 74 68 c\fR.-file in th
0770: 65 20 54 63 6c 20 73 6f 75 72 63 65 20 64 69 73 e Tcl source dis
0780: 74 72 69 62 75 74 69 6f 6e 20 66 6f 72 20 61 6e tribution for an
0790: 20 65 78 70 65 72 69 6d 65 6e 74 61 6c 20 69 6d experimental im
07a0: 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 0a 2d 6f 66 plementation.-of
07b0: 20 61 20 54 63 6c 20 22 54 68 72 65 61 64 22 20 a Tcl "Thread"
07c0: 70 61 63 6b 61 67 65 20 69 6d 70 6c 65 6d 65 6e package implemen
07d0: 74 69 6e 67 20 74 68 72 65 61 64 20 63 72 65 61 ting thread crea
07e0: 74 69 6f 6e 20 61 6e 64 20 6d 61 6e 61 67 65 6d tion and managem
07f0: 65 6e 74 0a 2d 63 6f 6d 6d 61 6e 64 73 20 61 74 ent.-commands at
0800: 20 74 68 65 20 73 63 72 69 70 74 20 6c 65 76 65 the script leve
0810: 6c 2e 0a 2b 2e 56 53 20 38 2e 35 0a 2b 54 63 6c l..+.VS 8.5.+Tcl
0820: 20 70 72 6f 76 69 64 65 73 20 6e 6f 20 62 75 69 provides no bui
0830: 6c 74 2d 69 6e 20 63 6f 6d 6d 61 6e 64 73 20 66 lt-in commands f
0840: 6f 72 20 73 63 72 69 70 74 73 20 74 6f 20 75 73 or scripts to us
0850: 65 20 74 6f 20 63 72 65 61 74 65 2c 20 6d 61 6e e to create, man
0860: 61 67 65 2c 0a 2b 6f 72 20 6a 6f 69 6e 20 74 68 age,.+or join th
0870: 72 65 61 64 73 2c 20 6e 6f 72 20 61 6e 79 20 73 reads, nor any s
0880: 63 72 69 70 74 2d 6c 65 76 65 6c 20 61 63 63 65 cript-level acce
0890: 73 73 20 74 6f 20 6d 75 74 65 78 20 6f 72 20 63 ss to mutex or c
08a0: 6f 6e 64 69 74 69 6f 6e 20 76 61 72 69 61 62 6c ondition variabl
08b0: 65 73 2e 0a 2b 49 74 20 70 72 6f 76 69 64 65 73 es..+It provides
08c0: 20 73 75 63 68 20 66 61 63 69 6c 69 74 69 65 73 such facilities
08d0: 20 6f 6e 6c 79 20 76 69 61 20 43 20 69 6e 74 65 only via C inte
08e0: 72 66 61 63 65 73 2c 20 61 6e 64 20 6c 65 61 76 rfaces, and leav
08f0: 65 73 20 69 74 20 75 70 20 74 6f 0a 2b 70 61 63 es it up to.+pac
0900: 6b 61 67 65 73 20 74 6f 20 65 78 70 6f 73 65 20 kages to expose
0910: 74 68 65 73 65 20 6d 61 74 74 65 72 73 20 74 6f these matters to
0920: 20 74 68 65 20 73 63 72 69 70 74 20 6c 65 76 65 the script leve
0930: 6c 2e 20 20 4f 6e 65 20 73 75 63 68 20 70 61 63 l. One such pac
0940: 6b 61 67 65 0a 2b 69 73 20 74 68 65 20 5c 66 42 kage.+is the \fB
0950: 54 68 72 65 61 64 5c 66 52 20 70 61 63 6b 61 67 Thread\fR packag
0960: 65 2e 0a 2b 2e 56 45 20 38 2e 35 0a 20 0a 20 2e e..+.VE 8.5. . .
0970: 53 48 20 44 45 53 43 52 49 50 54 49 4f 4e 0a 20 SH DESCRIPTION.
0980: 41 20 6d 75 74 65 78 20 69 73 20 61 20 6c 6f 63 A mutex is a loc
0990: 6b 20 74 68 61 74 20 69 73 20 75 73 65 64 20 74 k that is used t
09a0: 6f 20 73 65 72 69 61 6c 69 7a 65 20 61 6c 6c 20 o serialize all
09b0: 74 68 72 65 61 64 73 20 74 68 72 6f 75 67 68 20 threads through
09c0: 61 20 70 69 65 63 65 0a 20 6f 66 20 63 6f 64 65 a piece. of code
09d0: 20 62 79 20 63 61 6c 6c 69 6e 67 20 5c 66 42 54 by calling \fBT
09e0: 63 6c 5f 4d 75 74 65 78 4c 6f 63 6b 5c 66 52 20 cl_MutexLock\fR
09f0: 61 6e 64 20 5c 66 42 54 63 6c 5f 4d 75 74 65 78 and \fBTcl_Mutex
0a00: 55 6e 6c 6f 63 6b 5c 66 52 2e 0a 20 49 66 20 6f Unlock\fR.. If o
0a10: 6e 65 20 74 68 72 65 61 64 20 68 6f 6c 64 73 20 ne thread holds
0a20: 61 20 6d 75 74 65 78 2c 20 61 6e 79 20 6f 74 68 a mutex, any oth
0a30: 65 72 20 74 68 72 65 61 64 20 63 61 6c 6c 69 6e er thread callin
0a40: 67 20 5c 66 42 54 63 6c 5f 4d 75 74 65 78 4c 6f g \fBTcl_MutexLo
0a50: 63 6b 5c 66 52 20 77 69 6c 6c 0a 20 62 6c 6f 63 ck\fR will. bloc
0a60: 6b 20 75 6e 74 69 6c 20 5c 66 42 54 63 6c 5f 4d k until \fBTcl_M
0a70: 75 74 65 78 55 6e 6c 6f 63 6b 5c 66 52 20 69 73 utexUnlock\fR is
0a80: 20 63 61 6c 6c 65 64 2e 0a 2d 2e 56 53 0a 20 41 called..-.VS. A
0a90: 20 6d 75 74 65 78 20 63 61 6e 20 62 65 20 64 65 mutex can be de
0aa0: 73 74 72 6f 79 65 64 20 61 66 74 65 72 20 69 74 stroyed after it
0ab0: 73 20 75 73 65 20 62 79 20 63 61 6c 6c 69 6e 67 s use by calling
0ac0: 20 5c 66 42 54 63 6c 5f 4d 75 74 65 78 46 69 6e \fBTcl_MutexFin
0ad0: 61 6c 69 7a 65 5c 66 52 2e 0a 20 54 68 65 20 72 alize\fR.. The r
0ae0: 65 73 75 6c 74 20 6f 66 20 6c 6f 63 6b 69 6e 67 esult of locking
0af0: 20 61 20 6d 75 74 65 78 20 74 77 69 63 65 20 66 a mutex twice f
0b00: 72 6f 6d 20 74 68 65 20 73 61 6d 65 20 74 68 72 rom the same thr
0b10: 65 61 64 20 69 73 20 75 6e 64 65 66 69 6e 65 64 ead is undefined
0b20: 2e 0a 20 4f 6e 20 73 6f 6d 65 20 70 6c 61 74 66 .. On some platf
0b30: 6f 72 6d 73 20 69 74 20 77 69 6c 6c 20 72 65 73 orms it will res
0b40: 75 6c 74 20 69 6e 20 61 20 64 65 61 64 6c 6f 63 ult in a deadloc
0b50: 6b 2e 0a 2d 2e 56 45 0a 20 54 68 65 20 5c 66 42 k..-.VE. The \fB
0b60: 54 63 6c 5f 4d 75 74 65 78 4c 6f 63 6b 5c 66 52 Tcl_MutexLock\fR
0b70: 2c 20 5c 66 42 54 63 6c 5f 4d 75 74 65 78 55 6e , \fBTcl_MutexUn
0b80: 6c 6f 63 6b 5c 66 52 20 61 6e 64 20 5c 66 42 54 lock\fR and \fBT
0b90: 63 6c 5f 4d 75 74 65 78 46 69 6e 61 6c 69 7a 65 cl_MutexFinalize
0ba0: 5c 66 52 0a 20 70 72 6f 63 65 64 75 72 65 73 20 \fR. procedures
0bb0: 61 72 65 20 64 65 66 69 6e 65 64 20 61 73 20 65 are defined as e
0bc0: 6d 70 74 79 20 6d 61 63 72 6f 73 20 69 66 20 6e mpty macros if n
0bd0: 6f 74 20 63 6f 6d 70 69 6c 69 6e 67 20 77 69 74 ot compiling wit
0be0: 68 20 74 68 72 65 61 64 73 20 65 6e 61 62 6c 65 h threads enable
0bf0: 64 2e 0a 20 2e 50 50 0a 40 40 20 2d 31 37 32 2c d.. .PP.@@ -172,
0c00: 31 34 20 2b 31 36 36 2c 31 32 20 40 40 0a 20 6e 14 +166,12 @@. n
0c10: 6f 74 69 66 69 63 61 74 69 6f 6e 73 20 62 79 20 otifications by
0c20: 63 61 6c 6c 69 6e 67 20 5c 66 42 54 63 6c 5f 43 calling \fBTcl_C
0c30: 6f 6e 64 69 74 69 6f 6e 57 61 69 74 5c 66 52 20 onditionWait\fR
0c40: 77 69 74 68 69 6e 20 61 20 77 68 69 6c 65 20 6c within a while l
0c50: 6f 6f 70 0a 20 74 68 61 74 20 74 65 73 74 73 20 oop. that tests
0c60: 73 6f 6d 65 20 69 6e 76 61 72 69 61 6e 74 2e 0a some invariant..
0c70: 20 2e 50 50 0a 2d 2e 56 53 0a 20 41 20 63 6f 6e .PP.-.VS. A con
0c80: 64 69 74 69 6f 6e 20 76 61 72 69 61 62 6c 65 20 dition variable
0c90: 63 61 6e 20 62 65 20 64 65 73 74 72 6f 79 65 64 can be destroyed
0ca0: 20 61 66 74 65 72 20 69 74 73 20 75 73 65 20 62 after its use b
0cb0: 79 20 63 61 6c 6c 69 6e 67 0a 20 5c 66 42 54 63 y calling. \fBTc
0cc0: 6c 5f 43 6f 6e 64 69 74 69 6f 6e 46 69 6e 61 6c l_ConditionFinal
0cd0: 69 7a 65 5c 66 52 2e 0a 20 2e 50 50 0a 20 54 68 ize\fR.. .PP. Th
0ce0: 65 20 5c 66 42 54 63 6c 5f 43 6f 6e 64 69 74 69 e \fBTcl_Conditi
0cf0: 6f 6e 4e 6f 74 69 66 79 5c 66 52 2c 20 5c 66 42 onNotify\fR, \fB
0d00: 54 63 6c 5f 43 6f 6e 64 69 74 69 6f 6e 57 61 69 Tcl_ConditionWai
0d10: 74 5c 66 52 20 61 6e 64 0a 20 5c 66 42 54 63 6c t\fR and. \fBTcl
0d20: 5f 43 6f 6e 64 69 74 69 6f 6e 46 69 6e 61 6c 69 _ConditionFinali
0d30: 7a 65 5c 66 52 20 70 72 6f 63 65 64 75 72 65 73 ze\fR procedures
0d40: 20 61 72 65 20 64 65 66 69 6e 65 64 20 61 73 20 are defined as
0d50: 65 6d 70 74 79 20 6d 61 63 72 6f 73 20 69 66 0a empty macros if.
0d60: 20 6e 6f 74 20 63 6f 6d 70 69 6c 69 6e 67 20 77 not compiling w
0d70: 69 74 68 20 74 68 72 65 61 64 73 20 65 6e 61 62 ith threads enab
0d80: 6c 65 64 2e 0a 2d 2e 56 45 0a 20 2e 50 50 0a 20 led..-.VE. .PP.
0d90: 54 68 65 20 5c 66 42 54 63 6c 5f 47 65 74 54 68 The \fBTcl_GetTh
0da0: 72 65 61 64 44 61 74 61 5c 66 52 20 63 61 6c 6c readData\fR call
0db0: 20 72 65 74 75 72 6e 73 20 61 20 70 6f 69 6e 74 returns a point
0dc0: 65 72 20 74 6f 20 61 20 62 6c 6f 63 6b 20 6f 66 er to a block of
0dd0: 0a 20 74 68 72 65 61 64 2d 70 72 69 76 61 74 65 . thread-private
0de0: 20 64 61 74 61 2e 20 20 49 74 73 20 61 72 67 75 data. Its argu
0df0: 6d 65 6e 74 20 69 73 20 61 20 6b 65 79 20 74 68 ment is a key th
0e00: 61 74 20 69 73 20 73 68 61 72 65 64 20 62 79 20 at is shared by
0e10: 61 6c 6c 20 74 68 72 65 61 64 73 0a 40 40 20 2d all threads.@@ -
0e20: 31 39 32 2c 32 30 20 2b 31 38 34 2c 31 33 20 40 192,20 +184,13 @
0e30: 40 0a 20 54 68 65 79 20 61 72 65 20 69 6d 70 6c @. They are impl
0e40: 65 6d 65 6e 74 65 64 20 61 73 20 6f 70 61 71 75 emented as opaqu
0e50: 65 20 70 6f 69 6e 74 65 72 73 20 74 68 61 74 20 e pointers that
0e60: 73 68 6f 75 6c 64 20 62 65 20 4e 55 4c 4c 0a 20 should be NULL.
0e70: 75 70 6f 6e 20 66 69 72 73 74 20 75 73 65 2e 0a upon first use..
0e80: 20 54 68 65 20 6d 75 74 65 78 65 73 20 61 6e 64 The mutexes and
0e90: 20 63 6f 6e 64 69 74 69 6f 6e 20 76 61 72 69 61 condition varia
0ea0: 62 6c 65 73 20 61 72 65 0a 2d 2e 56 53 0a 20 65 bles are.-.VS. e
0eb0: 69 74 68 65 72 20 63 6c 65 61 6e 65 64 20 75 70 ither cleaned up
0ec0: 20 62 79 20 70 72 6f 63 65 73 73 20 65 78 69 74 by process exit
0ed0: 20 68 61 6e 64 6c 65 72 73 20 28 69 66 20 6c 69 handlers (if li
0ee0: 76 69 6e 67 20 74 68 61 74 20 6c 6f 6e 67 29 20 ving that long)
0ef0: 6f 72 0a 20 65 78 70 6c 69 63 69 74 6c 79 20 62 or. explicitly b
0f00: 79 20 63 61 6c 6c 73 20 74 6f 20 5c 66 42 54 63 y calls to \fBTc
0f10: 6c 5f 4d 75 74 65 78 46 69 6e 61 6c 69 7a 65 5c l_MutexFinalize\
0f20: 66 52 20 6f 72 0a 20 5c 66 42 54 63 6c 5f 43 6f fR or. \fBTcl_Co
0f30: 6e 64 69 74 69 6f 6e 46 69 6e 61 6c 69 7a 65 5c nditionFinalize\
0f40: 66 52 2e 0a 2d 2e 56 45 0a 20 54 68 72 65 61 64 fR..-.VE. Thread
0f50: 20 6c 6f 63 61 6c 20 73 74 6f 72 61 67 65 20 69 local storage i
0f60: 73 20 72 65 63 6c 61 69 6d 65 64 20 64 75 72 69 s reclaimed duri
0f70: 6e 67 20 5c 66 42 54 63 6c 5f 46 69 6e 61 6c 69 ng \fBTcl_Finali
0f80: 7a 65 54 68 72 65 61 64 5c 66 52 2e 0a 2d 2e 53 zeThread\fR..-.S
0f90: 48 20 22 43 52 45 41 54 49 4e 47 20 54 48 52 45 H "CREATING THRE
0fa0: 41 44 53 22 0a 2d 54 68 65 20 41 50 49 20 74 6f ADS".-The API to
0fb0: 20 63 72 65 61 74 65 20 74 68 72 65 61 64 73 20 create threads
0fc0: 69 73 20 6e 6f 74 20 66 69 6e 61 6c 69 7a 65 64 is not finalized
0fd0: 20 61 74 20 74 68 69 73 20 74 69 6d 65 2e 0a 2d at this time..-
0fe0: 54 68 65 72 65 20 61 72 65 20 70 72 69 76 61 74 There are privat
0ff0: 65 20 66 61 63 69 6c 69 74 69 65 73 20 74 6f 20 e facilities to
1000: 63 72 65 61 74 65 20 74 68 72 65 61 64 73 20 74 create threads t
1010: 68 61 74 20 63 6f 6e 74 61 69 6e 20 61 20 6e 65 hat contain a ne
1020: 77 0a 2d 54 63 6c 20 69 6e 74 65 72 70 72 65 74 w.-Tcl interpret
1030: 65 72 2c 20 61 6e 64 20 74 6f 20 73 65 6e 64 20 er, and to send
1040: 73 63 72 69 70 74 73 20 61 6d 6f 6e 67 20 74 68 scripts among th
1050: 72 65 61 64 73 2e 0a 2d 44 69 76 65 20 69 6e 74 reads..-Dive int
1060: 6f 20 74 63 6c 54 68 72 65 61 64 54 65 73 74 2e o tclThreadTest.
1070: 63 20 61 6e 64 20 74 63 6c 54 68 72 65 61 64 2e c and tclThread.
1080: 63 20 66 6f 72 20 65 78 61 6d 70 6c 65 73 2e 0a c for examples..
1090: 20 2e 53 48 20 22 53 45 45 20 41 4c 53 4f 22 0a .SH "SEE ALSO".
10a0: 20 54 63 6c 5f 47 65 74 43 75 72 72 65 6e 74 54 Tcl_GetCurrentT
10b0: 68 72 65 61 64 2c 20 54 63 6c 5f 54 68 72 65 61 hread, Tcl_Threa
10c0: 64 51 75 65 75 65 45 76 65 6e 74 2c 20 54 63 6c dQueueEvent, Tcl
10d0: 5f 54 68 72 65 61 64 41 6c 65 72 74 2c 0a 20 54 _ThreadAlert,. T
10e0: 63 6c 5f 45 78 69 74 54 68 72 65 61 64 2c 20 54 cl_ExitThread, T
10f0: 63 6c 5f 46 69 6e 61 6c 69 7a 65 54 68 72 65 61 cl_FinalizeThrea
1100: 64 2c 0a 2d 54 63 6c 5f 43 72 65 61 74 65 54 68 d,.-Tcl_CreateTh
1110: 72 65 61 64 45 78 69 74 48 61 6e 64 6c 65 72 2c readExitHandler,
1120: 20 54 63 6c 5f 44 65 6c 65 74 65 54 68 72 65 61 Tcl_DeleteThrea
1130: 64 45 78 69 74 48 61 6e 64 6c 65 72 0a 2b 54 63 dExitHandler.+Tc
1140: 6c 5f 43 72 65 61 74 65 54 68 72 65 61 64 45 78 l_CreateThreadEx
1150: 69 74 48 61 6e 64 6c 65 72 2c 20 54 63 6c 5f 44 itHandler, Tcl_D
1160: 65 6c 65 74 65 54 68 72 65 61 64 45 78 69 74 48 eleteThreadExitH
1170: 61 6e 64 6c 65 72 2c 20 54 68 72 65 61 64 0a 20 andler, Thread.
1180: 2e 53 48 20 4b 45 59 57 4f 52 44 53 0a 20 74 68 .SH KEYWORDS. th
1190: 72 65 61 64 2c 20 6d 75 74 65 78 2c 20 63 6f 6e read, mutex, con
11a0: 64 69 74 69 6f 6e 20 76 61 72 69 61 62 6c 65 2c dition variable,
11b0: 20 74 68 72 65 61 64 20 6c 6f 63 61 6c 20 73 74 thread local st
11c0: 6f 72 61 67 65 0a orage.