Attachment "tcl.all_threads_blocked.patch" to
ticket [8bd13f07bd]
added by
stanko
2014-02-18 19:21:43.
0000: 49 6e 64 65 78 3a 20 77 69 6e 2f 74 63 6c 57 69 Index: win/tclWi
0010: 6e 43 6f 6e 73 6f 6c 65 2e 63 0d 0a 3d 3d 3d 3d nConsole.c..====
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 3d 3d 3d 3d 3d 3d 3d 0d 0a ==============..
0060: 2d 2d 2d 20 77 69 6e 2f 74 63 6c 57 69 6e 43 6f --- win/tclWinCo
0070: 6e 73 6f 6c 65 2e 63 0d 0a 2b 2b 2b 20 77 69 6e nsole.c..+++ win
0080: 2f 74 63 6c 57 69 6e 43 6f 6e 73 6f 6c 65 2e 63 /tclWinConsole.c
0090: 0d 0a 40 40 20 2d 34 39 2c 31 30 20 2b 34 39 2c ..@@ -49,10 +49,
00a0: 31 32 20 40 40 0d 0a 20 20 2a 20 74 68 72 65 61 12 @@.. * threa
00b0: 64 73 2e 0d 0a 20 20 2a 2f 0d 0a 20 0d 0a 20 74 ds... */.. .. t
00c0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 43 6f ypedef struct Co
00d0: 6e 73 6f 6c 65 54 68 72 65 61 64 49 6e 66 6f 20 nsoleThreadInfo
00e0: 7b 0d 0a 20 20 20 20 20 48 41 4e 44 4c 45 20 74 {.. HANDLE t
00f0: 68 72 65 61 64 3b 09 09 2f 2a 20 48 61 6e 64 6c hread;../* Handl
0100: 65 20 74 6f 20 72 65 61 64 65 72 20 6f 72 20 77 e to reader or w
0110: 72 69 74 65 72 20 74 68 72 65 61 64 2e 20 2a 2f riter thread. */
0120: 0d 0a 2b 20 20 20 20 48 41 4e 44 4c 45 20 74 68 ..+ HANDLE th
0130: 72 65 61 64 49 6e 69 74 69 61 6c 69 7a 65 64 3b readInitialized;
0140: 09 2f 2a 20 4d 61 6e 75 61 6c 2d 72 65 73 65 74 ./* Manual-reset
0150: 20 65 76 65 6e 74 20 74 6f 20 73 69 67 6e 61 6c event to signal
0160: 20 74 68 61 74 20 74 68 72 65 61 64 20 68 61 73 that thread has
0170: 20 62 65 65 6e 20 69 6e 69 74 69 61 6c 69 7a 65 been initialize
0180: 64 2e 20 2a 2f 0d 0a 2b 20 20 20 20 69 6e 74 20 d. */..+ int
0190: 74 68 72 65 61 64 45 78 69 74 69 6e 67 3b 09 09 threadExiting;..
01a0: 2f 2a 20 42 6f 6f 6c 65 61 6e 20 69 6e 64 69 63 /* Boolean indic
01b0: 61 74 69 6e 67 20 74 68 61 74 20 74 68 72 65 61 ating that threa
01c0: 64 20 69 73 20 65 78 69 74 69 6e 67 2e 20 2a 2f d is exiting. */
01d0: 0d 0a 20 20 20 20 20 48 41 4e 44 4c 45 20 72 65 .. HANDLE re
01e0: 61 64 79 45 76 65 6e 74 3b 09 09 2f 2a 20 4d 61 adyEvent;../* Ma
01f0: 6e 75 61 6c 2d 72 65 73 65 74 20 65 76 65 6e 74 nual-reset event
0200: 20 74 6f 20 73 69 67 6e 61 6c 20 5f 74 6f 5f 20 to signal _to_
0210: 74 68 65 20 6d 61 69 6e 0d 0a 20 09 09 09 09 20 the main.. ....
0220: 2a 20 74 68 72 65 61 64 20 77 68 65 6e 20 74 68 * thread when th
0230: 65 20 77 6f 72 6b 65 72 20 74 68 72 65 61 64 20 e worker thread
0240: 68 61 73 20 66 69 6e 69 73 68 65 64 0d 0a 20 09 has finished.. .
0250: 09 09 09 20 2a 20 77 61 69 74 69 6e 67 20 66 6f ... * waiting fo
0260: 72 20 69 74 73 20 6e 6f 72 6d 61 6c 20 77 6f 72 r its normal wor
0270: 6b 20 74 6f 20 68 61 70 70 65 6e 2e 20 2a 2f 0d k to happen. */.
0280: 0a 20 20 20 20 20 48 41 4e 44 4c 45 20 73 74 61 . HANDLE sta
0290: 72 74 45 76 65 6e 74 3b 09 09 2f 2a 20 41 75 74 rtEvent;../* Aut
02a0: 6f 2d 72 65 73 65 74 20 65 76 65 6e 74 20 75 73 o-reset event us
02b0: 65 64 20 62 79 20 74 68 65 20 6d 61 69 6e 20 74 ed by the main t
02c0: 68 72 65 61 64 20 74 6f 0d 0a 20 09 09 09 09 20 hread to.. ....
02d0: 2a 20 73 69 67 6e 61 6c 20 77 68 65 6e 20 74 68 * signal when th
02e0: 65 20 74 68 72 65 61 64 20 73 68 6f 75 6c 64 20 e thread should
02f0: 61 74 74 65 6d 70 74 20 74 6f 20 64 6f 0d 0a 40 attempt to do..@
0300: 40 20 2d 35 32 33 2c 31 32 20 2b 35 32 35 2c 31 @ -523,12 +525,1
0310: 35 20 40 40 0d 0a 20 20 20 20 20 44 57 4f 52 44 5 @@.. DWORD
0320: 20 69 64 3b 0d 0a 20 0d 0a 20 20 20 20 20 74 68 id;.. .. th
0330: 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e 72 65 61 readInfoPtr->rea
0340: 64 79 45 76 65 6e 74 20 3d 20 43 72 65 61 74 65 dyEvent = Create
0350: 45 76 65 6e 74 28 4e 55 4c 4c 2c 20 54 52 55 45 Event(NULL, TRUE
0360: 2c 20 54 52 55 45 2c 20 4e 55 4c 4c 29 3b 0d 0a , TRUE, NULL);..
0370: 20 20 20 20 20 74 68 72 65 61 64 49 6e 66 6f 50 threadInfoP
0380: 74 72 2d 3e 73 74 61 72 74 45 76 65 6e 74 20 3d tr->startEvent =
0390: 20 43 72 65 61 74 65 45 76 65 6e 74 28 4e 55 4c CreateEvent(NUL
03a0: 4c 2c 20 46 41 4c 53 45 2c 20 46 41 4c 53 45 2c L, FALSE, FALSE,
03b0: 20 4e 55 4c 4c 29 3b 0d 0a 20 20 20 20 20 74 68 NULL);.. th
03c0: 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e 73 74 6f readInfoPtr->sto
03d0: 70 45 76 65 6e 74 20 3d 20 43 72 65 61 74 65 45 pEvent = CreateE
03e0: 76 65 6e 74 28 4e 55 4c 4c 2c 20 46 41 4c 53 45 vent(NULL, FALSE
03f0: 2c 20 46 41 4c 53 45 2c 20 4e 55 4c 4c 29 3b 0d , FALSE, NULL);.
0400: 0a 2b 20 20 20 20 74 68 72 65 61 64 49 6e 66 6f .+ threadInfo
0410: 50 74 72 2d 3e 74 68 72 65 61 64 49 6e 69 74 69 Ptr->threadIniti
0420: 61 6c 69 7a 65 64 20 3d 20 43 72 65 61 74 65 45 alized = CreateE
0430: 76 65 6e 74 28 4e 55 4c 4c 2c 20 54 52 55 45 2c vent(NULL, TRUE,
0440: 20 46 41 4c 53 45 2c 20 4e 55 4c 4c 29 3b 0d 0a FALSE, NULL);..
0450: 2b 20 20 20 20 74 68 72 65 61 64 49 6e 66 6f 50 + threadInfoP
0460: 74 72 2d 3e 74 68 72 65 61 64 45 78 69 74 69 6e tr->threadExitin
0470: 67 20 3d 20 46 41 4c 53 45 3b 0d 0a 20 20 20 20 g = FALSE;..
0480: 20 74 68 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e threadInfoPtr->
0490: 74 68 72 65 61 64 20 3d 20 43 72 65 61 74 65 54 thread = CreateT
04a0: 68 72 65 61 64 28 4e 55 4c 4c 2c 20 32 35 36 2c hread(NULL, 256,
04b0: 20 74 68 72 65 61 64 50 72 6f 63 2c 20 69 6e 66 threadProc, inf
04c0: 6f 50 74 72 2c 20 30 2c 0d 0a 20 09 20 20 20 20 oPtr, 0,.. .
04d0: 26 69 64 29 3b 0d 0a 2b 20 20 20 20 57 61 69 74 &id);..+ Wait
04e0: 46 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 ForSingleObject(
04f0: 74 68 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e 74 threadInfoPtr->t
0500: 68 72 65 61 64 49 6e 69 74 69 61 6c 69 7a 65 64 hreadInitialized
0510: 2c 20 49 4e 46 49 4e 49 54 45 29 3b 20 2f 2a 20 , INFINITE); /*
0520: 77 61 69 74 20 66 6f 72 20 74 68 72 65 61 64 20 wait for thread
0530: 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 2a 2f to initialize */
0540: 0d 0a 20 20 20 20 20 53 65 74 54 68 72 65 61 64 .. SetThread
0550: 50 72 69 6f 72 69 74 79 28 74 68 72 65 61 64 49 Priority(threadI
0560: 6e 66 6f 50 74 72 2d 3e 74 68 72 65 61 64 2c 20 nfoPtr->thread,
0570: 54 48 52 45 41 44 5f 50 52 49 4f 52 49 54 59 5f THREAD_PRIORITY_
0580: 48 49 47 48 45 53 54 29 3b 0d 0a 20 7d 0d 0a 20 HIGHEST);.. }..
0590: 0d 0a 20 73 74 61 74 69 63 20 76 6f 69 64 0d 0a .. static void..
05a0: 20 53 74 6f 70 43 68 61 6e 6e 65 6c 54 68 72 65 StopChannelThre
05b0: 61 64 28 0d 0a 40 40 20 2d 35 35 38 2c 31 35 20 ad(..@@ -558,15
05c0: 2b 35 36 33 2c 33 32 20 40 40 0d 0a 20 09 20 20 +563,32 @@.. .
05d0: 20 20 2f 2a 0d 0a 20 09 20 20 20 20 20 2a 20 46 /*.. . * F
05e0: 6f 72 63 69 62 6c 79 20 74 65 72 6d 69 6e 61 74 orcibly terminat
05f0: 65 20 74 68 65 20 62 61 63 6b 67 72 6f 75 6e 64 e the background
0600: 20 74 68 72 65 61 64 20 61 73 20 61 20 6c 61 73 thread as a las
0610: 74 20 72 65 73 6f 72 74 2e 0d 0a 20 09 20 20 20 t resort... .
0620: 20 20 2a 20 4e 6f 74 65 20 74 68 61 74 20 77 65 * Note that we
0630: 20 6e 65 65 64 20 74 6f 20 67 75 61 72 64 20 61 need to guard a
0640: 67 61 69 6e 73 74 20 74 65 72 6d 69 6e 61 74 69 gainst terminati
0650: 6e 67 20 74 68 65 20 74 68 72 65 61 64 20 77 68 ng the thread wh
0660: 69 6c 65 0d 0a 20 09 20 20 20 20 20 2a 20 69 74 ile.. . * it
0670: 20 69 73 20 69 6e 20 74 68 65 20 6d 69 64 64 6c is in the middl
0680: 65 20 6f 66 20 54 63 6c 5f 54 68 72 65 61 64 41 e of Tcl_ThreadA
0690: 6c 65 72 74 20 62 65 63 61 75 73 65 20 69 74 20 lert because it
06a0: 77 6f 6e 27 74 20 62 65 20 61 62 6c 65 0d 0a 20 won't be able..
06b0: 09 20 20 20 20 20 2a 20 74 6f 20 72 65 6c 65 61 . * to relea
06c0: 73 65 20 74 68 65 20 6e 6f 74 69 66 69 65 72 20 se the notifier
06d0: 6c 6f 63 6b 2e 0d 0a 2b 09 20 20 20 20 20 2a 0d lock...+. *.
06e0: 0a 2b 09 20 20 20 20 20 2a 20 41 6c 73 6f 20 6e .+. * Also n
06f0: 6f 74 65 20 74 68 61 74 20 74 65 72 6d 69 6e 61 ote that termina
0700: 74 69 6e 67 20 74 68 72 65 61 64 73 20 64 75 72 ting threads dur
0710: 69 6e 67 20 74 68 65 69 72 20 69 6e 69 74 69 61 ing their initia
0720: 6c 69 7a 61 74 69 6f 6e 20 6f 72 20 74 65 61 72 lization or tear
0730: 64 6f 77 6e 20 70 68 61 73 65 0d 0a 2b 09 20 20 down phase..+.
0740: 20 20 20 2a 20 6d 61 79 20 72 65 73 75 6c 74 20 * may result
0750: 69 6e 20 6e 74 64 6c 6c 2e 64 6c 6c 27 73 20 4c in ntdll.dll's L
0760: 6f 61 64 65 72 4c 6f 63 6b 20 74 6f 20 72 65 6d oaderLock to rem
0770: 61 69 6e 20 6c 6f 63 6b 65 64 20 69 6e 64 65 66 ain locked indef
0780: 69 6e 69 74 65 6c 79 2e 0d 0a 2b 09 20 20 20 20 initely...+.
0790: 20 2a 20 54 68 69 73 20 63 61 75 73 65 73 20 6e * This causes n
07a0: 74 64 6c 6c 2e 64 6c 6c 27 73 20 4c 64 72 70 49 tdll.dll's LdrpI
07b0: 6e 69 74 69 61 6c 69 7a 65 54 68 72 65 61 64 28 nitializeThread(
07c0: 29 20 74 6f 20 64 65 61 64 6c 6f 63 6b 20 74 72 ) to deadlock tr
07d0: 79 69 6e 67 20 74 6f 20 61 63 71 75 69 72 65 20 ying to acquire
07e0: 4c 6f 61 64 65 72 4c 6f 63 6b 2e 0d 0a 2b 09 20 LoaderLock...+.
07f0: 20 20 20 20 2a 20 4c 64 72 70 49 6e 69 74 69 61 * LdrpInitia
0800: 6c 69 7a 65 54 68 72 65 61 64 28 29 20 69 73 20 lizeThread() is
0810: 65 78 65 63 75 74 65 64 20 77 69 74 68 69 6e 20 executed within
0820: 6e 65 77 20 74 68 72 65 61 64 73 20 74 6f 20 70 new threads to p
0830: 65 72 66 6f 72 6d 0d 0a 2b 09 20 20 20 20 20 2a erform..+. *
0840: 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 initialization
0850: 61 6e 64 20 74 6f 20 65 78 65 63 75 74 65 20 44 and to execute D
0860: 6c 6c 4d 61 69 6e 28 29 20 6f 66 20 61 6c 6c 20 llMain() of all
0870: 6c 6f 61 64 65 64 20 64 6c 6c 73 2e 0d 0a 2b 09 loaded dlls...+.
0880: 20 20 20 20 20 2a 20 41 73 20 61 20 72 65 73 75 * As a resu
0890: 6c 74 2c 20 61 6c 6c 20 6e 65 77 20 74 68 72 65 lt, all new thre
08a0: 61 64 73 20 61 72 65 20 64 65 61 64 6c 6f 63 6b ads are deadlock
08b0: 65 64 20 69 6e 20 74 68 65 69 72 20 69 6e 69 74 ed in their init
08c0: 69 61 6c 69 7a 61 74 69 6f 6e 20 70 68 61 73 65 ialization phase
08d0: 20 61 6e 64 20 6e 65 76 65 72 20 65 78 65 63 75 and never execu
08e0: 74 65 2c 0d 0a 2b 09 20 20 20 20 20 2a 20 65 76 te,..+. * ev
08f0: 65 6e 20 74 68 6f 75 67 68 20 43 72 65 61 74 65 en though Create
0900: 54 68 72 65 61 64 28 29 20 72 65 70 6f 72 74 73 Thread() reports
0910: 20 73 75 63 63 65 73 73 66 75 6c 20 74 68 72 65 successful thre
0920: 61 64 20 63 72 65 61 74 69 6f 6e 2e 0d 0a 2b 09 ad creation...+.
0930: 20 20 20 20 20 2a 20 54 68 69 73 20 72 65 73 75 * This resu
0940: 6c 74 73 20 69 6e 20 61 20 76 65 72 79 20 77 65 lts in a very we
0950: 69 72 64 20 70 72 6f 63 65 73 73 2d 77 69 64 65 ird process-wide
0960: 20 62 65 68 61 76 69 6f 72 2c 20 77 68 69 63 68 behavior, which
0970: 20 69 73 20 65 78 74 72 65 6d 65 6c 79 20 68 61 is extremely ha
0980: 72 64 20 74 6f 20 64 65 62 75 67 2e 0d 0a 2b 09 rd to debug...+.
0990: 20 20 20 20 20 2a 20 0d 0a 2b 09 20 20 20 20 20 * ..+.
09a0: 2a 20 54 48 52 45 41 44 53 20 53 48 4f 55 4c 44 * THREADS SHOULD
09b0: 20 4e 45 56 45 52 20 42 45 20 54 45 52 4d 49 4e NEVER BE TERMIN
09c0: 41 54 45 44 2e 20 50 65 72 69 6f 64 2e 0d 0a 2b ATED. Period...+
09d0: 09 20 20 20 20 20 2a 20 0d 0a 2b 09 20 20 20 20 . * ..+.
09e0: 20 2a 20 42 75 74 20 66 6f 72 20 6e 6f 77 2c 20 * But for now,
09f0: 63 68 65 63 6b 20 69 66 20 74 68 72 65 61 64 20 check if thread
0a00: 69 73 20 65 78 69 74 69 6e 67 2c 20 61 6e 64 20 is exiting, and
0a10: 69 66 20 73 6f 2c 20 6c 65 74 20 69 74 20 64 69 if so, let it di
0a20: 65 20 70 65 61 63 65 66 75 6c 6c 79 2e 0d 0a 20 e peacefully...
0a30: 09 20 20 20 20 20 2a 2f 0d 0a 20 0d 0a 20 09 20 . */.. .. .
0a40: 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c 6f 63 6b Tcl_MutexLock
0a50: 28 26 63 6f 6e 73 6f 6c 65 4d 75 74 65 78 29 3b (&consoleMutex);
0a60: 0d 0a 2d 09 20 20 20 20 2f 2a 20 42 55 47 3a 20 ..-. /* BUG:
0a70: 74 68 69 73 20 6c 65 61 6b 73 20 6d 65 6d 6f 72 this leaks memor
0a80: 79 2e 20 2a 2f 0d 0a 2d 09 20 20 20 20 54 65 72 y. */..-. Ter
0a90: 6d 69 6e 61 74 65 54 68 72 65 61 64 28 74 68 72 minateThread(thr
0aa0: 65 61 64 49 6e 66 6f 50 74 72 2d 3e 74 68 72 65 eadInfoPtr->thre
0ab0: 61 64 2c 20 30 29 3b 0d 0a 2b 09 20 20 20 20 69 ad, 0);..+. i
0ac0: 66 20 28 20 74 68 72 65 61 64 49 6e 66 6f 50 74 f ( threadInfoPt
0ad0: 72 2d 3e 74 68 72 65 61 64 45 78 69 74 69 6e 67 r->threadExiting
0ae0: 20 29 20 7b 0d 0a 2b 09 09 20 20 20 20 57 61 69 ) {..+.. Wai
0af0: 74 46 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 63 74 tForSingleObject
0b00: 28 74 68 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e (threadInfoPtr->
0b10: 74 68 72 65 61 64 2c 20 49 4e 46 49 4e 49 54 45 thread, INFINITE
0b20: 29 3b 0d 0a 2b 09 20 20 20 20 7d 20 65 6c 73 65 );..+. } else
0b30: 20 7b 0d 0a 2b 09 09 20 20 20 20 2f 2a 20 42 55 {..+.. /* BU
0b40: 47 3a 20 74 68 69 73 20 6c 65 61 6b 73 20 6d 65 G: this leaks me
0b50: 6d 6f 72 79 2e 20 2a 2f 0d 0a 2b 09 09 20 20 20 mory. */..+..
0b60: 20 54 65 72 6d 69 6e 61 74 65 54 68 72 65 61 64 TerminateThread
0b70: 28 74 68 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e (threadInfoPtr->
0b80: 74 68 72 65 61 64 2c 20 30 29 3b 0d 0a 2b 09 20 thread, 0);..+.
0b90: 20 20 20 7d 0d 0a 20 09 20 20 20 20 54 63 6c 5f }.. . Tcl_
0ba0: 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 26 63 6f 6e MutexUnlock(&con
0bb0: 73 6f 6c 65 4d 75 74 65 78 29 3b 0d 0a 20 09 7d soleMutex);.. .}
0bc0: 0d 0a 20 20 20 20 20 7d 0d 0a 20 0d 0a 20 20 20 .. }.. ..
0bd0: 20 20 2f 2a 0d 0a 40 40 20 2d 35 37 33 2c 31 30 /*..@@ -573,10
0be0: 20 2b 35 39 35 2c 31 31 20 40 40 0d 0a 20 20 20 +595,11 @@..
0bf0: 20 20 20 2a 20 43 6c 6f 73 65 20 61 6c 6c 20 74 * Close all t
0c00: 68 65 20 68 61 6e 64 6c 65 73 20 61 73 73 6f 63 he handles assoc
0c10: 69 61 74 65 64 20 77 69 74 68 20 74 68 65 20 74 iated with the t
0c20: 68 72 65 61 64 2c 20 61 6e 64 20 73 65 74 20 74 hread, and set t
0c30: 68 65 20 74 68 72 65 61 64 0d 0a 20 20 20 20 20 he thread..
0c40: 20 2a 20 68 61 6e 64 6c 65 20 66 69 65 6c 64 20 * handle field
0c50: 74 6f 20 4e 55 4c 4c 20 74 6f 20 6d 61 72 6b 20 to NULL to mark
0c60: 74 68 61 74 20 74 68 65 20 74 68 72 65 61 64 20 that the thread
0c70: 68 61 73 20 62 65 65 6e 20 63 6c 65 61 6e 65 64 has been cleaned
0c80: 20 75 70 2e 0d 0a 20 20 20 20 20 20 2a 2f 0d 0a up... */..
0c90: 20 0d 0a 20 20 20 20 20 43 6c 6f 73 65 48 61 6e .. CloseHan
0ca0: 64 6c 65 28 74 68 72 65 61 64 49 6e 66 6f 50 74 dle(threadInfoPt
0cb0: 72 2d 3e 74 68 72 65 61 64 29 3b 0d 0a 2b 20 20 r->thread);..+
0cc0: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 74 68 CloseHandle(th
0cd0: 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e 74 68 72 readInfoPtr->thr
0ce0: 65 61 64 49 6e 69 74 69 61 6c 69 7a 65 64 29 3b eadInitialized);
0cf0: 0d 0a 20 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 .. CloseHand
0d00: 6c 65 28 74 68 72 65 61 64 49 6e 66 6f 50 74 72 le(threadInfoPtr
0d10: 2d 3e 72 65 61 64 79 45 76 65 6e 74 29 3b 0d 0a ->readyEvent);..
0d20: 20 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 CloseHandle
0d30: 28 74 68 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e (threadInfoPtr->
0d40: 73 74 61 72 74 45 76 65 6e 74 29 3b 0d 0a 20 20 startEvent);..
0d50: 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 74 CloseHandle(t
0d60: 68 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e 73 74 hreadInfoPtr->st
0d70: 6f 70 45 76 65 6e 74 29 3b 0d 0a 20 20 20 20 20 opEvent);..
0d80: 74 68 72 65 61 64 49 6e 66 6f 50 74 72 2d 3e 74 threadInfoPtr->t
0d90: 68 72 65 61 64 20 3d 20 4e 55 4c 4c 3b 0d 0a 20 hread = NULL;..
0da0: 7d 0d 0a 40 40 20 2d 31 31 36 34 2c 31 30 20 2b }..@@ -1164,10 +
0db0: 31 31 38 37 2c 31 35 20 40 40 0d 0a 20 20 20 20 1187,15 @@..
0dc0: 20 48 41 4e 44 4c 45 20 2a 68 61 6e 64 6c 65 20 HANDLE *handle
0dd0: 3d 20 69 6e 66 6f 50 74 72 2d 3e 68 61 6e 64 6c = infoPtr->handl
0de0: 65 3b 0d 0a 20 20 20 20 20 43 6f 6e 73 6f 6c 65 e;.. Console
0df0: 54 68 72 65 61 64 49 6e 66 6f 20 2a 74 68 72 65 ThreadInfo *thre
0e00: 61 64 49 6e 66 6f 20 3d 20 26 69 6e 66 6f 50 74 adInfo = &infoPt
0e10: 72 2d 3e 72 65 61 64 65 72 3b 0d 0a 20 20 20 20 r->reader;..
0e20: 20 44 57 4f 52 44 20 77 61 69 74 52 65 73 75 6c DWORD waitResul
0e30: 74 3b 0d 0a 20 20 20 20 20 48 41 4e 44 4c 45 20 t;.. HANDLE
0e40: 77 45 76 65 6e 74 73 5b 32 5d 3b 0d 0a 20 0d 0a wEvents[2];.. ..
0e50: 2b 20 20 20 20 2f 2a 0d 0a 2b 20 20 20 20 20 2a + /*..+ *
0e60: 20 4e 6f 74 69 66 79 20 53 74 61 72 74 43 68 61 Notify StartCha
0e70: 6e 6e 65 6c 54 68 72 65 61 64 28 29 20 74 68 61 nnelThread() tha
0e80: 74 20 74 68 69 73 20 74 68 72 65 61 64 20 69 73 t this thread is
0e90: 20 69 6e 69 74 69 61 6c 69 7a 65 64 0d 0a 2b 20 initialized..+
0ea0: 20 20 20 20 2a 2f 0d 0a 2b 20 20 20 20 53 65 74 */..+ Set
0eb0: 45 76 65 6e 74 28 74 68 72 65 61 64 49 6e 66 6f Event(threadInfo
0ec0: 2d 3e 74 68 72 65 61 64 49 6e 69 74 69 61 6c 69 ->threadInitiali
0ed0: 7a 65 64 29 3b 0d 0a 2b 0d 0a 20 20 20 20 20 2f zed);..+.. /
0ee0: 2a 0d 0a 20 20 20 20 20 20 2a 20 54 68 65 20 66 *.. * The f
0ef0: 69 72 73 74 20 65 76 65 6e 74 20 74 61 6b 65 73 irst event takes
0f00: 20 70 72 65 63 65 64 65 6e 63 65 2e 0d 0a 20 20 precedence...
0f10: 20 20 20 20 2a 2f 0d 0a 20 0d 0a 20 20 20 20 20 */.. ..
0f20: 77 45 76 65 6e 74 73 5b 30 5d 20 3d 20 74 68 72 wEvents[0] = thr
0f30: 65 61 64 49 6e 66 6f 2d 3e 73 74 6f 70 45 76 65 eadInfo->stopEve
0f40: 6e 74 3b 0d 0a 40 40 20 2d 31 32 33 32 2c 31 30 nt;..@@ -1232,10
0f50: 20 2b 31 32 36 30 2c 31 38 20 40 40 0d 0a 20 09 +1260,18 @@.. .
0f60: 20 20 20 20 54 63 6c 5f 54 68 72 65 61 64 41 6c Tcl_ThreadAl
0f70: 65 72 74 28 69 6e 66 6f 50 74 72 2d 3e 74 68 72 ert(infoPtr->thr
0f80: 65 61 64 49 64 29 3b 0d 0a 20 09 7d 0d 0a 20 09 eadId);.. .}.. .
0f90: 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 Tcl_MutexUnlock(
0fa0: 26 63 6f 6e 73 6f 6c 65 4d 75 74 65 78 29 3b 0d &consoleMutex);.
0fb0: 0a 20 20 20 20 20 7d 0d 0a 20 0d 0a 2b 20 20 20 . }.. ..+
0fc0: 20 2f 2a 0d 0a 2b 20 20 20 20 20 2a 20 49 6e 66 /*..+ * Inf
0fd0: 6f 72 6d 20 53 74 6f 70 43 68 61 6e 6e 65 6c 54 orm StopChannelT
0fe0: 68 72 65 61 64 28 29 20 74 68 61 74 20 74 68 69 hread() that thi
0ff0: 73 20 74 68 72 65 61 64 20 73 68 6f 75 6c 64 20 s thread should
1000: 6e 6f 74 20 62 65 20 74 65 72 6d 69 6e 61 74 65 not be terminate
1010: 64 2c 20 73 69 6e 63 65 20 69 74 20 69 73 20 61 d, since it is a
1020: 62 6f 75 74 20 74 6f 20 65 78 69 74 2e 0d 0a 2b bout to exit...+
1030: 20 20 20 20 20 2a 20 53 65 65 20 63 6f 6d 6d 65 * See comme
1040: 6e 74 20 69 6e 20 53 74 6f 70 43 68 61 6e 6e 65 nt in StopChanne
1050: 6c 54 68 72 65 61 64 28 29 20 66 6f 72 20 72 65 lThread() for re
1060: 61 73 6f 6e 73 2e 0d 0a 2b 20 20 20 20 2a 2f 0d asons...+ */.
1070: 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c .+ Tcl_MutexL
1080: 6f 63 6b 28 26 63 6f 6e 73 6f 6c 65 4d 75 74 65 ock(&consoleMute
1090: 78 29 3b 0d 0a 2b 20 20 20 20 74 68 72 65 61 64 x);..+ thread
10a0: 49 6e 66 6f 2d 3e 74 68 72 65 61 64 45 78 69 74 Info->threadExit
10b0: 69 6e 67 20 3d 20 54 52 55 45 3b 0d 0a 2b 20 20 ing = TRUE;..+
10c0: 20 20 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 Tcl_MutexUnloc
10d0: 6b 28 26 63 6f 6e 73 6f 6c 65 4d 75 74 65 78 29 k(&consoleMutex)
10e0: 3b 0d 0a 2b 0d 0a 20 20 20 20 20 72 65 74 75 72 ;..+.. retur
10f0: 6e 20 30 3b 0d 0a 20 7d 0d 0a 20 0c 0d 0a 20 2f n 0;.. }.. ... /
1100: 2a 0d 0a 20 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *.. *----------
1110: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 40 40 ------------..@@
1150: 20 2d 31 32 36 35 2c 31 30 20 2b 31 33 30 31 2c -1265,10 +1301,
1160: 31 35 20 40 40 0d 0a 20 20 20 20 20 43 6f 6e 73 15 @@.. Cons
1170: 6f 6c 65 54 68 72 65 61 64 49 6e 66 6f 20 2a 74 oleThreadInfo *t
1180: 68 72 65 61 64 49 6e 66 6f 20 3d 20 26 69 6e 66 hreadInfo = &inf
1190: 6f 50 74 72 2d 3e 77 72 69 74 65 72 3b 0d 0a 20 oPtr->writer;..
11a0: 20 20 20 20 44 57 4f 52 44 20 63 6f 75 6e 74 2c DWORD count,
11b0: 20 74 6f 57 72 69 74 65 2c 20 77 61 69 74 52 65 toWrite, waitRe
11c0: 73 75 6c 74 3b 0d 0a 20 20 20 20 20 63 68 61 72 sult;.. char
11d0: 20 2a 62 75 66 3b 0d 0a 20 20 20 20 20 48 41 4e *buf;.. HAN
11e0: 44 4c 45 20 77 45 76 65 6e 74 73 5b 32 5d 3b 0d DLE wEvents[2];.
11f0: 0a 20 0d 0a 2b 20 20 20 20 2f 2a 0d 0a 2b 20 20 . ..+ /*..+
1200: 20 20 20 2a 20 4e 6f 74 69 66 79 20 53 74 61 72 * Notify Star
1210: 74 43 68 61 6e 6e 65 6c 54 68 72 65 61 64 28 29 tChannelThread()
1220: 20 74 68 61 74 20 74 68 69 73 20 74 68 72 65 61 that this threa
1230: 64 20 69 73 20 69 6e 69 74 69 61 6c 69 7a 65 64 d is initialized
1240: 0d 0a 2b 20 20 20 20 20 2a 2f 0d 0a 2b 20 20 20 ..+ */..+
1250: 20 53 65 74 45 76 65 6e 74 28 74 68 72 65 61 64 SetEvent(thread
1260: 49 6e 66 6f 2d 3e 74 68 72 65 61 64 49 6e 69 74 Info->threadInit
1270: 69 61 6c 69 7a 65 64 29 3b 0d 0a 2b 0d 0a 20 20 ialized);..+..
1280: 20 20 20 2f 2a 0d 0a 20 20 20 20 20 20 2a 20 54 /*.. * T
1290: 68 65 20 66 69 72 73 74 20 65 76 65 6e 74 20 74 he first event t
12a0: 61 6b 65 73 20 70 72 65 63 65 64 65 6e 63 65 2e akes precedence.
12b0: 0d 0a 20 20 20 20 20 20 2a 2f 0d 0a 20 0d 0a 20 .. */.. ..
12c0: 20 20 20 20 77 45 76 65 6e 74 73 5b 30 5d 20 3d wEvents[0] =
12d0: 20 74 68 72 65 61 64 49 6e 66 6f 2d 3e 73 74 6f threadInfo->sto
12e0: 70 45 76 65 6e 74 3b 0d 0a 40 40 20 2d 31 33 33 pEvent;..@@ -133
12f0: 30 2c 31 30 20 2b 31 33 37 31 2c 31 38 20 40 40 0,10 +1371,18 @@
1300: 0d 0a 20 09 20 20 20 20 54 63 6c 5f 54 68 72 65 .. . Tcl_Thre
1310: 61 64 41 6c 65 72 74 28 69 6e 66 6f 50 74 72 2d adAlert(infoPtr-
1320: 3e 74 68 72 65 61 64 49 64 29 3b 0d 0a 20 09 7d >threadId);.. .}
1330: 0d 0a 20 09 54 63 6c 5f 4d 75 74 65 78 55 6e 6c .. .Tcl_MutexUnl
1340: 6f 63 6b 28 26 63 6f 6e 73 6f 6c 65 4d 75 74 65 ock(&consoleMute
1350: 78 29 3b 0d 0a 20 20 20 20 20 7d 0d 0a 20 0d 0a x);.. }.. ..
1360: 2b 20 20 20 20 2f 2a 0d 0a 2b 20 20 20 20 20 2a + /*..+ *
1370: 20 49 6e 66 6f 72 6d 20 53 74 6f 70 43 68 61 6e Inform StopChan
1380: 6e 65 6c 54 68 72 65 61 64 28 29 20 74 68 61 74 nelThread() that
1390: 20 74 68 69 73 20 74 68 72 65 61 64 20 73 68 6f this thread sho
13a0: 75 6c 64 20 6e 6f 74 20 62 65 20 74 65 72 6d 69 uld not be termi
13b0: 6e 61 74 65 64 2c 20 73 69 6e 63 65 20 69 74 20 nated, since it
13c0: 69 73 20 61 62 6f 75 74 20 74 6f 20 65 78 69 74 is about to exit
13d0: 2e 0d 0a 2b 20 20 20 20 20 2a 20 53 65 65 20 63 ...+ * See c
13e0: 6f 6d 6d 65 6e 74 20 69 6e 20 53 74 6f 70 43 68 omment in StopCh
13f0: 61 6e 6e 65 6c 54 68 72 65 61 64 28 29 20 66 6f annelThread() fo
1400: 72 20 72 65 61 73 6f 6e 73 2e 0d 0a 2b 20 20 20 r reasons...+
1410: 20 2a 2f 0d 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 */..+ Tcl_Mu
1420: 74 65 78 4c 6f 63 6b 28 26 63 6f 6e 73 6f 6c 65 texLock(&console
1430: 4d 75 74 65 78 29 3b 0d 0a 2b 20 20 20 20 74 68 Mutex);..+ th
1440: 72 65 61 64 49 6e 66 6f 2d 3e 74 68 72 65 61 64 readInfo->thread
1450: 45 78 69 74 69 6e 67 20 3d 20 54 52 55 45 3b 0d Exiting = TRUE;.
1460: 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 55 .+ Tcl_MutexU
1470: 6e 6c 6f 63 6b 28 26 63 6f 6e 73 6f 6c 65 4d 75 nlock(&consoleMu
1480: 74 65 78 29 3b 0d 0a 2b 0d 0a 20 20 20 20 20 72 tex);..+.. r
1490: 65 74 75 72 6e 20 30 3b 0d 0a 20 7d 0d 0a 20 0c eturn 0;.. }.. .
14a0: 0d 0a 20 2f 2a 0d 0a 20 20 2a 2d 2d 2d 2d 2d 2d .. /*.. *------
14b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14f0: 0d 0a 0d 0a 49 6e 64 65 78 3a 20 77 69 6e 2f 74 ....Index: win/t
1500: 63 6c 57 69 6e 50 69 70 65 2e 63 0d 0a 3d 3d 3d clWinPipe.c..===
1510: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
1520: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
1530: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
1540: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0d ===============.
1550: 0a 2d 2d 2d 20 77 69 6e 2f 74 63 6c 57 69 6e 50 .--- win/tclWinP
1560: 69 70 65 2e 63 0d 0a 2b 2b 2b 20 77 69 6e 2f 74 ipe.c..+++ win/t
1570: 63 6c 57 69 6e 50 69 70 65 2e 63 0d 0a 40 40 20 clWinPipe.c..@@
1580: 2d 31 30 33 2c 31 30 20 2b 31 30 33 2c 31 34 20 -103,10 +103,14
1590: 40 40 0d 0a 20 20 20 20 20 54 63 6c 5f 54 68 72 @@.. Tcl_Thr
15a0: 65 61 64 49 64 20 74 68 72 65 61 64 49 64 3b 09 eadId threadId;.
15b0: 2f 2a 20 54 68 72 65 61 64 20 74 6f 20 77 68 69 /* Thread to whi
15c0: 63 68 20 65 76 65 6e 74 73 20 73 68 6f 75 6c 64 ch events should
15d0: 20 62 65 20 72 65 70 6f 72 74 65 64 2e 0d 0a 20 be reported...
15e0: 09 09 09 09 20 2a 20 54 68 69 73 20 76 61 6c 75 .... * This valu
15f0: 65 20 69 73 20 75 73 65 64 20 62 79 20 74 68 65 e is used by the
1600: 20 72 65 61 64 65 72 2f 77 72 69 74 65 72 0d 0a reader/writer..
1610: 20 09 09 09 09 20 2a 20 74 68 72 65 61 64 73 2e .... * threads.
1620: 20 2a 2f 0d 0a 20 20 20 20 20 48 41 4e 44 4c 45 */.. HANDLE
1630: 20 77 72 69 74 65 54 68 72 65 61 64 3b 09 09 2f writeThread;../
1640: 2a 20 48 61 6e 64 6c 65 20 74 6f 20 77 72 69 74 * Handle to writ
1650: 65 72 20 74 68 72 65 61 64 2e 20 2a 2f 0d 0a 20 er thread. */..
1660: 20 20 20 20 48 41 4e 44 4c 45 20 72 65 61 64 54 HANDLE readT
1670: 68 72 65 61 64 3b 09 09 2f 2a 20 48 61 6e 64 6c hread;../* Handl
1680: 65 20 74 6f 20 72 65 61 64 65 72 20 74 68 72 65 e to reader thre
1690: 61 64 2e 20 2a 2f 0d 0a 2b 20 20 20 20 48 41 4e ad. */..+ HAN
16a0: 44 4c 45 20 77 72 69 74 65 54 68 72 65 61 64 49 DLE writeThreadI
16b0: 6e 69 74 69 61 6c 69 7a 65 64 3b 09 2f 2a 20 4d nitialized;./* M
16c0: 61 6e 75 61 6c 2d 72 65 73 65 74 20 65 76 65 6e anual-reset even
16d0: 74 20 74 6f 20 73 69 67 6e 61 6c 20 74 68 61 74 t to signal that
16e0: 20 77 72 69 74 65 72 20 74 68 72 65 61 64 20 68 writer thread h
16f0: 61 73 20 62 65 65 6e 20 69 6e 69 74 69 61 6c 69 as been initiali
1700: 7a 65 64 20 2a 2f 0d 0a 2b 20 20 20 20 48 41 4e zed */..+ HAN
1710: 44 4c 45 20 72 65 61 64 54 68 72 65 61 64 49 6e DLE readThreadIn
1720: 69 74 69 61 6c 69 7a 65 64 3b 09 2f 2a 20 4d 61 itialized;./* Ma
1730: 6e 75 61 6c 2d 72 65 73 65 74 20 65 76 65 6e 74 nual-reset event
1740: 20 74 6f 20 73 69 67 6e 61 6c 20 74 68 61 74 20 to signal that
1750: 72 65 61 64 65 72 20 74 68 72 65 61 64 20 68 61 reader thread ha
1760: 73 20 62 65 65 6e 20 69 6e 69 74 69 61 6c 69 7a s been initializ
1770: 65 64 20 2a 2f 0d 0a 2b 20 20 20 20 69 6e 74 20 ed */..+ int
1780: 77 72 69 74 65 54 68 72 65 61 64 45 78 69 74 69 writeThreadExiti
1790: 6e 67 3b 09 2f 2a 20 42 6f 6f 6c 65 61 6e 20 69 ng;./* Boolean i
17a0: 6e 64 69 63 61 74 69 6e 67 20 74 68 61 74 20 77 ndicating that w
17b0: 72 69 74 65 20 74 68 72 65 61 64 20 69 73 20 65 rite thread is e
17c0: 78 69 74 69 6e 67 20 2a 2f 0d 0a 2b 20 20 20 20 xiting */..+
17d0: 69 6e 74 20 72 65 61 64 54 68 72 65 61 64 45 78 int readThreadEx
17e0: 69 74 69 6e 67 3b 09 2f 2a 20 42 6f 6f 6c 65 61 iting;./* Boolea
17f0: 6e 20 69 6e 64 69 63 61 74 69 6e 67 20 74 68 61 n indicating tha
1800: 74 20 72 65 61 64 20 74 68 72 65 61 64 20 69 73 t read thread is
1810: 20 65 78 69 74 69 6e 67 20 2a 2f 0d 0a 20 20 20 exiting */..
1820: 20 20 48 41 4e 44 4c 45 20 77 72 69 74 61 62 6c HANDLE writabl
1830: 65 3b 09 09 2f 2a 20 4d 61 6e 75 61 6c 2d 72 65 e;../* Manual-re
1840: 73 65 74 20 65 76 65 6e 74 20 74 6f 20 73 69 67 set event to sig
1850: 6e 61 6c 20 77 68 65 6e 20 74 68 65 0d 0a 20 09 nal when the.. .
1860: 09 09 09 20 2a 20 77 72 69 74 65 72 20 74 68 72 ... * writer thr
1870: 65 61 64 20 68 61 73 20 66 69 6e 69 73 68 65 64 ead has finished
1880: 20 77 61 69 74 69 6e 67 20 66 6f 72 20 74 68 65 waiting for the
1890: 0d 0a 20 09 09 09 09 20 2a 20 63 75 72 72 65 6e .. .... * curren
18a0: 74 20 62 75 66 66 65 72 20 74 6f 20 62 65 20 77 t buffer to be w
18b0: 72 69 74 74 65 6e 2e 20 2a 2f 0d 0a 20 20 20 20 ritten. */..
18c0: 20 48 41 4e 44 4c 45 20 72 65 61 64 61 62 6c 65 HANDLE readable
18d0: 3b 09 09 2f 2a 20 4d 61 6e 75 61 6c 2d 72 65 73 ;../* Manual-res
18e0: 65 74 20 65 76 65 6e 74 20 74 6f 20 73 69 67 6e et event to sign
18f0: 61 6c 20 77 68 65 6e 20 74 68 65 0d 0a 20 09 09 al when the.. ..
1900: 09 09 20 2a 20 72 65 61 64 65 72 20 74 68 72 65 .. * reader thre
1910: 61 64 20 68 61 73 20 66 69 6e 69 73 68 65 64 20 ad has finished
1920: 77 61 69 74 69 6e 67 20 66 6f 72 0d 0a 40 40 20 waiting for..@@
1930: 2d 31 35 39 32 2c 31 32 20 2b 31 35 39 36 2c 31 -1592,12 +1596,1
1940: 35 20 40 40 0d 0a 20 09 20 2a 2f 0d 0a 20 0d 0a 5 @@.. . */.. ..
1950: 20 09 69 6e 66 6f 50 74 72 2d 3e 72 65 61 64 61 .infoPtr->reada
1960: 62 6c 65 20 3d 20 43 72 65 61 74 65 45 76 65 6e ble = CreateEven
1970: 74 28 4e 55 4c 4c 2c 20 54 52 55 45 2c 20 54 52 t(NULL, TRUE, TR
1980: 55 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 20 09 69 6e UE, NULL);.. .in
1990: 66 6f 50 74 72 2d 3e 73 74 61 72 74 52 65 61 64 foPtr->startRead
19a0: 65 72 20 3d 20 43 72 65 61 74 65 45 76 65 6e 74 er = CreateEvent
19b0: 28 4e 55 4c 4c 2c 20 46 41 4c 53 45 2c 20 46 41 (NULL, FALSE, FA
19c0: 4c 53 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 20 09 69 LSE, NULL);.. .i
19d0: 6e 66 6f 50 74 72 2d 3e 73 74 6f 70 52 65 61 64 nfoPtr->stopRead
19e0: 65 72 20 3d 20 43 72 65 61 74 65 45 76 65 6e 74 er = CreateEvent
19f0: 28 4e 55 4c 4c 2c 20 54 52 55 45 2c 20 46 41 4c (NULL, TRUE, FAL
1a00: 53 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 2b 09 69 6e SE, NULL);..+.in
1a10: 66 6f 50 74 72 2d 3e 72 65 61 64 54 68 72 65 61 foPtr->readThrea
1a20: 64 49 6e 69 74 69 61 6c 69 7a 65 64 20 3d 20 43 dInitialized = C
1a30: 72 65 61 74 65 45 76 65 6e 74 28 4e 55 4c 4c 2c reateEvent(NULL,
1a40: 20 54 52 55 45 2c 20 46 41 4c 53 45 2c 20 4e 55 TRUE, FALSE, NU
1a50: 4c 4c 29 3b 0d 0a 2b 09 69 6e 66 6f 50 74 72 2d LL);..+.infoPtr-
1a60: 3e 72 65 61 64 54 68 72 65 61 64 45 78 69 74 69 >readThreadExiti
1a70: 6e 67 20 3d 20 46 41 4c 53 45 3b 0d 0a 20 09 69 ng = FALSE;.. .i
1a80: 6e 66 6f 50 74 72 2d 3e 72 65 61 64 54 68 72 65 nfoPtr->readThre
1a90: 61 64 20 3d 20 43 72 65 61 74 65 54 68 72 65 61 ad = CreateThrea
1aa0: 64 28 4e 55 4c 4c 2c 20 32 35 36 2c 20 50 69 70 d(NULL, 256, Pip
1ab0: 65 52 65 61 64 65 72 54 68 72 65 61 64 2c 0d 0a eReaderThread,..
1ac0: 20 09 09 69 6e 66 6f 50 74 72 2c 20 30 2c 20 26 ..infoPtr, 0, &
1ad0: 69 64 29 3b 0d 0a 2b 09 57 61 69 74 46 6f 72 53 id);..+.WaitForS
1ae0: 69 6e 67 6c 65 4f 62 6a 65 63 74 28 69 6e 66 6f ingleObject(info
1af0: 50 74 72 2d 3e 72 65 61 64 54 68 72 65 61 64 49 Ptr->readThreadI
1b00: 6e 69 74 69 61 6c 69 7a 65 64 2c 20 49 4e 46 49 nitialized, INFI
1b10: 4e 49 54 45 29 3b 20 2f 2a 20 77 61 69 74 20 66 NITE); /* wait f
1b20: 6f 72 20 74 68 72 65 61 64 20 74 6f 20 69 6e 69 or thread to ini
1b30: 74 69 61 6c 69 7a 65 20 2a 2f 0d 0a 20 09 53 65 tialize */.. .Se
1b40: 74 54 68 72 65 61 64 50 72 69 6f 72 69 74 79 28 tThreadPriority(
1b50: 69 6e 66 6f 50 74 72 2d 3e 72 65 61 64 54 68 72 infoPtr->readThr
1b60: 65 61 64 2c 20 54 48 52 45 41 44 5f 50 52 49 4f ead, THREAD_PRIO
1b70: 52 49 54 59 5f 48 49 47 48 45 53 54 29 3b 0d 0a RITY_HIGHEST);..
1b80: 20 09 69 6e 66 6f 50 74 72 2d 3e 76 61 6c 69 64 .infoPtr->valid
1b90: 4d 61 73 6b 20 7c 3d 20 54 43 4c 5f 52 45 41 44 Mask |= TCL_READ
1ba0: 41 42 4c 45 3b 0d 0a 20 20 20 20 20 7d 20 65 6c ABLE;.. } el
1bb0: 73 65 20 7b 0d 0a 20 09 69 6e 66 6f 50 74 72 2d se {.. .infoPtr-
1bc0: 3e 72 65 61 64 54 68 72 65 61 64 20 3d 20 30 3b >readThread = 0;
1bd0: 0d 0a 20 20 20 20 20 7d 0d 0a 40 40 20 2d 31 36 .. }..@@ -16
1be0: 30 37 2c 31 32 20 2b 31 36 31 34 2c 31 35 20 40 07,12 +1614,15 @
1bf0: 40 0d 0a 20 09 20 2a 2f 0d 0a 20 0d 0a 20 09 69 @.. . */.. .. .i
1c00: 6e 66 6f 50 74 72 2d 3e 77 72 69 74 61 62 6c 65 nfoPtr->writable
1c10: 20 3d 20 43 72 65 61 74 65 45 76 65 6e 74 28 4e = CreateEvent(N
1c20: 55 4c 4c 2c 20 54 52 55 45 2c 20 54 52 55 45 2c ULL, TRUE, TRUE,
1c30: 20 4e 55 4c 4c 29 3b 0d 0a 20 09 69 6e 66 6f 50 NULL);.. .infoP
1c40: 74 72 2d 3e 73 74 61 72 74 57 72 69 74 65 72 20 tr->startWriter
1c50: 3d 20 43 72 65 61 74 65 45 76 65 6e 74 28 4e 55 = CreateEvent(NU
1c60: 4c 4c 2c 20 46 41 4c 53 45 2c 20 46 41 4c 53 45 LL, FALSE, FALSE
1c70: 2c 20 4e 55 4c 4c 29 3b 0d 0a 20 09 69 6e 66 6f , NULL);.. .info
1c80: 50 74 72 2d 3e 73 74 6f 70 57 72 69 74 65 72 20 Ptr->stopWriter
1c90: 3d 20 43 72 65 61 74 65 45 76 65 6e 74 28 4e 55 = CreateEvent(NU
1ca0: 4c 4c 2c 20 54 52 55 45 2c 20 46 41 4c 53 45 2c LL, TRUE, FALSE,
1cb0: 20 4e 55 4c 4c 29 3b 0d 0a 2b 09 69 6e 66 6f 50 NULL);..+.infoP
1cc0: 74 72 2d 3e 77 72 69 74 65 54 68 72 65 61 64 49 tr->writeThreadI
1cd0: 6e 69 74 69 61 6c 69 7a 65 64 20 3d 20 43 72 65 nitialized = Cre
1ce0: 61 74 65 45 76 65 6e 74 28 4e 55 4c 4c 2c 20 54 ateEvent(NULL, T
1cf0: 52 55 45 2c 20 46 41 4c 53 45 2c 20 4e 55 4c 4c RUE, FALSE, NULL
1d00: 29 3b 0d 0a 2b 09 69 6e 66 6f 50 74 72 2d 3e 77 );..+.infoPtr->w
1d10: 72 69 74 65 54 68 72 65 61 64 45 78 69 74 69 6e riteThreadExitin
1d20: 67 20 3d 20 46 41 4c 53 45 3b 0d 0a 20 09 69 6e g = FALSE;.. .in
1d30: 66 6f 50 74 72 2d 3e 77 72 69 74 65 54 68 72 65 foPtr->writeThre
1d40: 61 64 20 3d 20 43 72 65 61 74 65 54 68 72 65 61 ad = CreateThrea
1d50: 64 28 4e 55 4c 4c 2c 20 32 35 36 2c 20 50 69 70 d(NULL, 256, Pip
1d60: 65 57 72 69 74 65 72 54 68 72 65 61 64 2c 0d 0a eWriterThread,..
1d70: 20 09 09 69 6e 66 6f 50 74 72 2c 20 30 2c 20 26 ..infoPtr, 0, &
1d80: 69 64 29 3b 0d 0a 2b 09 57 61 69 74 46 6f 72 53 id);..+.WaitForS
1d90: 69 6e 67 6c 65 4f 62 6a 65 63 74 28 69 6e 66 6f ingleObject(info
1da0: 50 74 72 2d 3e 77 72 69 74 65 54 68 72 65 61 64 Ptr->writeThread
1db0: 49 6e 69 74 69 61 6c 69 7a 65 64 2c 20 49 4e 46 Initialized, INF
1dc0: 49 4e 49 54 45 29 3b 20 2f 2a 20 77 61 69 74 20 INITE); /* wait
1dd0: 66 6f 72 20 74 68 72 65 61 64 20 74 6f 20 69 6e for thread to in
1de0: 69 74 69 61 6c 69 7a 65 20 2a 2f 0d 0a 20 09 53 itialize */.. .S
1df0: 65 74 54 68 72 65 61 64 50 72 69 6f 72 69 74 79 etThreadPriority
1e00: 28 69 6e 66 6f 50 74 72 2d 3e 72 65 61 64 54 68 (infoPtr->readTh
1e10: 72 65 61 64 2c 20 54 48 52 45 41 44 5f 50 52 49 read, THREAD_PRI
1e20: 4f 52 49 54 59 5f 48 49 47 48 45 53 54 29 3b 0d ORITY_HIGHEST);.
1e30: 0a 20 09 69 6e 66 6f 50 74 72 2d 3e 76 61 6c 69 . .infoPtr->vali
1e40: 64 4d 61 73 6b 20 7c 3d 20 54 43 4c 5f 57 52 49 dMask |= TCL_WRI
1e50: 54 41 42 4c 45 3b 0d 0a 20 20 20 20 20 7d 0d 0a TABLE;.. }..
1e60: 20 0d 0a 20 20 20 20 20 2f 2a 0d 0a 40 40 20 2d .. /*..@@ -
1e70: 31 38 34 34 2c 32 31 20 2b 31 38 35 34 2c 33 38 1844,21 +1854,38
1e80: 20 40 40 0d 0a 20 09 09 20 20 20 20 20 2a 20 75 @@.. .. * u
1e90: 6e 74 69 6c 20 61 20 62 65 74 74 65 72 20 73 6f ntil a better so
1ea0: 6c 75 74 69 6f 6e 20 69 73 20 66 6f 75 6e 64 2e lution is found.
1eb0: 0d 0a 20 09 09 20 20 20 20 20 2a 0d 0a 20 09 09 .. .. *.. ..
1ec0: 20 20 20 20 20 2a 20 4e 6f 74 65 20 74 68 61 74 * Note that
1ed0: 20 77 65 20 6e 65 65 64 20 74 6f 20 67 75 61 72 we need to guar
1ee0: 64 20 61 67 61 69 6e 73 74 20 74 65 72 6d 69 6e d against termin
1ef0: 61 74 69 6e 67 20 74 68 65 0d 0a 20 09 09 20 20 ating the.. ..
1f00: 20 20 20 2a 20 74 68 72 65 61 64 20 77 68 69 6c * thread whil
1f10: 65 20 69 74 20 69 73 20 69 6e 20 74 68 65 20 6d e it is in the m
1f20: 69 64 64 6c 65 20 6f 66 20 54 63 6c 5f 54 68 72 iddle of Tcl_Thr
1f30: 65 61 64 41 6c 65 72 74 0d 0a 20 09 09 20 20 20 eadAlert.. ..
1f40: 20 20 2a 20 62 65 63 61 75 73 65 20 69 74 20 77 * because it w
1f50: 6f 6e 27 74 20 62 65 20 61 62 6c 65 20 74 6f 20 on't be able to
1f60: 72 65 6c 65 61 73 65 20 74 68 65 20 6e 6f 74 69 release the noti
1f70: 66 69 65 72 20 6c 6f 63 6b 2e 0d 0a 2b 09 09 20 fier lock...+..
1f80: 20 20 20 20 2a 0d 0a 2b 09 09 20 20 20 20 20 2a *..+.. *
1f90: 20 41 6c 73 6f 20 6e 6f 74 65 20 74 68 61 74 20 Also note that
1fa0: 74 65 72 6d 69 6e 61 74 69 6e 67 20 74 68 72 65 terminating thre
1fb0: 61 64 73 20 64 75 72 69 6e 67 20 74 68 65 69 72 ads during their
1fc0: 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 initialization
1fd0: 6f 72 20 74 65 61 72 64 6f 77 6e 20 70 68 61 73 or teardown phas
1fe0: 65 0d 0a 2b 09 09 20 20 20 20 20 2a 20 6d 61 79 e..+.. * may
1ff0: 20 72 65 73 75 6c 74 20 69 6e 20 6e 74 64 6c 6c result in ntdll
2000: 2e 64 6c 6c 27 73 20 4c 6f 61 64 65 72 4c 6f 63 .dll's LoaderLoc
2010: 6b 20 74 6f 20 72 65 6d 61 69 6e 20 6c 6f 63 6b k to remain lock
2020: 65 64 20 69 6e 64 65 66 69 6e 69 74 65 6c 79 2e ed indefinitely.
2030: 0d 0a 2b 09 09 20 20 20 20 20 2a 20 54 68 69 73 ..+.. * This
2040: 20 63 61 75 73 65 73 20 6e 74 64 6c 6c 2e 64 6c causes ntdll.dl
2050: 6c 27 73 20 4c 64 72 70 49 6e 69 74 69 61 6c 69 l's LdrpInitiali
2060: 7a 65 54 68 72 65 61 64 28 29 20 74 6f 20 64 65 zeThread() to de
2070: 61 64 6c 6f 63 6b 20 74 72 79 69 6e 67 20 74 6f adlock trying to
2080: 20 61 63 71 75 69 72 65 20 4c 6f 61 64 65 72 4c acquire LoaderL
2090: 6f 63 6b 2e 0d 0a 2b 09 09 20 20 20 20 20 2a 20 ock...+.. *
20a0: 4c 64 72 70 49 6e 69 74 69 61 6c 69 7a 65 54 68 LdrpInitializeTh
20b0: 72 65 61 64 28 29 20 69 73 20 65 78 65 63 75 74 read() is execut
20c0: 65 64 20 77 69 74 68 69 6e 20 6e 65 77 20 74 68 ed within new th
20d0: 72 65 61 64 73 20 74 6f 20 70 65 72 66 6f 72 6d reads to perform
20e0: 0d 0a 2b 09 09 20 20 20 20 20 2a 20 69 6e 69 74 ..+.. * init
20f0: 69 61 6c 69 7a 61 74 69 6f 6e 20 61 6e 64 20 74 ialization and t
2100: 6f 20 65 78 65 63 75 74 65 20 44 6c 6c 4d 61 69 o execute DllMai
2110: 6e 28 29 20 6f 66 20 61 6c 6c 20 6c 6f 61 64 65 n() of all loade
2120: 64 20 64 6c 6c 73 2e 0d 0a 2b 09 09 20 20 20 20 d dlls...+..
2130: 20 2a 20 41 73 20 61 20 72 65 73 75 6c 74 2c 20 * As a result,
2140: 61 6c 6c 20 6e 65 77 20 74 68 72 65 61 64 73 20 all new threads
2150: 61 72 65 20 64 65 61 64 6c 6f 63 6b 65 64 20 69 are deadlocked i
2160: 6e 20 74 68 65 69 72 20 69 6e 69 74 69 61 6c 69 n their initiali
2170: 7a 61 74 69 6f 6e 20 70 68 61 73 65 20 61 6e 64 zation phase and
2180: 20 6e 65 76 65 72 20 65 78 65 63 75 74 65 2c 0d never execute,.
2190: 0a 2b 09 09 20 20 20 20 20 2a 20 65 76 65 6e 20 .+.. * even
21a0: 74 68 6f 75 67 68 20 43 72 65 61 74 65 54 68 72 though CreateThr
21b0: 65 61 64 28 29 20 72 65 70 6f 72 74 73 20 73 75 ead() reports su
21c0: 63 63 65 73 73 66 75 6c 20 74 68 72 65 61 64 20 ccessful thread
21d0: 63 72 65 61 74 69 6f 6e 2e 0d 0a 2b 09 09 20 20 creation...+..
21e0: 20 20 20 2a 20 54 68 69 73 20 72 65 73 75 6c 74 * This result
21f0: 73 20 69 6e 20 61 20 76 65 72 79 20 77 65 69 72 s in a very weir
2200: 64 20 70 72 6f 63 65 73 73 2d 77 69 64 65 20 62 d process-wide b
2210: 65 68 61 76 69 6f 72 2c 20 77 68 69 63 68 20 69 ehavior, which i
2220: 73 20 65 78 74 72 65 6d 65 6c 79 20 68 61 72 64 s extremely hard
2230: 20 74 6f 20 64 65 62 75 67 2e 0d 0a 2b 09 09 20 to debug...+..
2240: 20 20 20 20 2a 20 0d 0a 2b 09 09 20 20 20 20 20 * ..+..
2250: 2a 20 54 48 52 45 41 44 53 20 53 48 4f 55 4c 44 * THREADS SHOULD
2260: 20 4e 45 56 45 52 20 42 45 20 54 45 52 4d 49 4e NEVER BE TERMIN
2270: 41 54 45 44 2e 20 50 65 72 69 6f 64 2e 0d 0a 2b ATED. Period...+
2280: 09 09 20 20 20 20 20 2a 20 0d 0a 2b 09 09 20 20 .. * ..+..
2290: 20 20 20 2a 20 42 75 74 20 66 6f 72 20 6e 6f 77 * But for now
22a0: 2c 20 63 68 65 63 6b 20 69 66 20 74 68 72 65 61 , check if threa
22b0: 64 20 69 73 20 65 78 69 74 69 6e 67 2c 20 61 6e d is exiting, an
22c0: 64 20 69 66 20 73 6f 2c 20 6c 65 74 20 69 74 20 d if so, let it
22d0: 64 69 65 20 70 65 61 63 65 66 75 6c 6c 79 2e 0d die peacefully..
22e0: 0a 20 09 09 20 20 20 20 20 2a 2f 0d 0a 20 0d 0a . .. */.. ..
22f0: 20 09 09 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 .. Tcl_Mutex
2300: 4c 6f 63 6b 28 26 70 69 70 65 4d 75 74 65 78 29 Lock(&pipeMutex)
2310: 3b 0d 0a 2d 0d 0a 2d 09 09 20 20 20 20 2f 2a 20 ;..-..-.. /*
2320: 42 55 47 3a 20 74 68 69 73 20 6c 65 61 6b 73 20 BUG: this leaks
2330: 6d 65 6d 6f 72 79 20 2a 2f 0d 0a 2d 09 09 20 20 memory */..-..
2340: 20 20 54 65 72 6d 69 6e 61 74 65 54 68 72 65 61 TerminateThrea
2350: 64 28 70 69 70 65 50 74 72 2d 3e 72 65 61 64 54 d(pipePtr->readT
2360: 68 72 65 61 64 2c 20 30 29 3b 0d 0a 2b 09 09 20 hread, 0);..+..
2370: 20 20 20 69 66 20 28 20 70 69 70 65 50 74 72 2d if ( pipePtr-
2380: 3e 72 65 61 64 54 68 72 65 61 64 45 78 69 74 69 >readThreadExiti
2390: 6e 67 20 29 20 7b 0d 0a 2b 09 09 09 20 20 20 20 ng ) {..+...
23a0: 57 61 69 74 46 6f 72 53 69 6e 67 6c 65 4f 62 6a WaitForSingleObj
23b0: 65 63 74 28 70 69 70 65 50 74 72 2d 3e 72 65 61 ect(pipePtr->rea
23c0: 64 54 68 72 65 61 64 2c 20 49 4e 46 49 4e 49 54 dThread, INFINIT
23d0: 45 29 3b 0d 0a 2b 09 09 20 20 20 20 7d 20 65 6c E);..+.. } el
23e0: 73 65 20 7b 0d 0a 2b 09 09 09 20 20 20 20 2f 2a se {..+... /*
23f0: 20 42 55 47 3a 20 74 68 69 73 20 6c 65 61 6b 73 BUG: this leaks
2400: 20 6d 65 6d 6f 72 79 20 2a 2f 0d 0a 2b 09 09 09 memory */..+...
2410: 20 20 20 20 54 65 72 6d 69 6e 61 74 65 54 68 72 TerminateThr
2420: 65 61 64 28 70 69 70 65 50 74 72 2d 3e 72 65 61 ead(pipePtr->rea
2430: 64 54 68 72 65 61 64 2c 20 30 29 3b 0d 0a 2b 09 dThread, 0);..+.
2440: 09 20 20 20 20 7d 0d 0a 20 09 09 20 20 20 20 54 . }.. .. T
2450: 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 26 cl_MutexUnlock(&
2460: 70 69 70 65 4d 75 74 65 78 29 3b 0d 0a 20 09 09 pipeMutex);.. ..
2470: 7d 0d 0a 20 09 20 20 20 20 7d 0d 0a 20 0d 0a 20 }.. . }.. ..
2480: 09 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 . CloseHandle
2490: 28 70 69 70 65 50 74 72 2d 3e 72 65 61 64 54 68 (pipePtr->readTh
24a0: 72 65 61 64 29 3b 0d 0a 2b 09 20 20 20 20 43 6c read);..+. Cl
24b0: 6f 73 65 48 61 6e 64 6c 65 28 70 69 70 65 50 74 oseHandle(pipePt
24c0: 72 2d 3e 72 65 61 64 54 68 72 65 61 64 49 6e 69 r->readThreadIni
24d0: 74 69 61 6c 69 7a 65 64 29 3b 0d 0a 20 09 20 20 tialized);.. .
24e0: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 CloseHandle(pi
24f0: 70 65 50 74 72 2d 3e 72 65 61 64 61 62 6c 65 29 pePtr->readable)
2500: 3b 0d 0a 20 09 20 20 20 20 43 6c 6f 73 65 48 61 ;.. . CloseHa
2510: 6e 64 6c 65 28 70 69 70 65 50 74 72 2d 3e 73 74 ndle(pipePtr->st
2520: 61 72 74 52 65 61 64 65 72 29 3b 0d 0a 20 09 20 artReader);.. .
2530: 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 CloseHandle(p
2540: 69 70 65 50 74 72 2d 3e 73 74 6f 70 52 65 61 64 ipePtr->stopRead
2550: 65 72 29 3b 0d 0a 20 09 20 20 20 20 70 69 70 65 er);.. . pipe
2560: 50 74 72 2d 3e 72 65 61 64 54 68 72 65 61 64 20 Ptr->readThread
2570: 3d 20 4e 55 4c 4c 3b 0d 0a 20 09 7d 0d 0a 40 40 = NULL;.. .}..@@
2580: 20 2d 31 39 30 30 2c 31 32 20 2b 31 39 32 37 2c -1900,12 +1927,
2590: 31 32 20 40 40 0d 0a 20 0d 0a 20 09 20 20 20 20 12 @@.. .. .
25a0: 47 65 74 45 78 69 74 43 6f 64 65 54 68 72 65 61 GetExitCodeThrea
25b0: 64 28 70 69 70 65 50 74 72 2d 3e 77 72 69 74 65 d(pipePtr->write
25c0: 54 68 72 65 61 64 2c 20 26 65 78 69 74 43 6f 64 Thread, &exitCod
25d0: 65 29 3b 0d 0a 20 0d 0a 20 09 20 20 20 20 69 66 e);.. .. . if
25e0: 20 28 65 78 69 74 43 6f 64 65 20 3d 3d 20 53 54 (exitCode == ST
25f0: 49 4c 4c 5f 41 43 54 49 56 45 29 20 7b 0d 0a 20 ILL_ACTIVE) {..
2600: 09 09 2f 2a 0d 0a 2d 09 09 20 2a 20 53 65 74 20 ../*..-.. * Set
2610: 74 68 65 20 73 74 6f 70 20 65 76 65 6e 74 20 73 the stop event s
2620: 6f 20 74 68 61 74 20 69 66 20 74 68 65 20 72 65 o that if the re
2630: 61 64 65 72 20 74 68 72 65 61 64 20 69 73 20 62 ader thread is b
2640: 6c 6f 63 6b 65 64 0d 0a 2d 09 09 20 2a 20 69 6e locked..-.. * in
2650: 20 50 69 70 65 52 65 61 64 65 72 54 68 72 65 61 PipeReaderThrea
2660: 64 20 6f 6e 20 57 61 69 74 46 6f 72 4d 75 6c 74 d on WaitForMult
2670: 69 70 6c 65 45 76 65 6e 74 73 2c 20 69 74 20 77 ipleEvents, it w
2680: 69 6c 6c 20 65 78 69 74 0d 0a 2b 09 09 20 2a 20 ill exit..+.. *
2690: 53 65 74 20 74 68 65 20 73 74 6f 70 20 65 76 65 Set the stop eve
26a0: 6e 74 20 73 6f 20 74 68 61 74 20 69 66 20 74 68 nt so that if th
26b0: 65 20 77 72 69 74 65 72 20 74 68 72 65 61 64 20 e writer thread
26c0: 69 73 20 62 6c 6f 63 6b 65 64 0d 0a 2b 09 09 20 is blocked..+..
26d0: 2a 20 69 6e 20 50 69 70 65 57 72 69 74 65 72 54 * in PipeWriterT
26e0: 68 72 65 61 64 20 6f 6e 20 57 61 69 74 46 6f 72 hread on WaitFor
26f0: 4d 75 6c 74 69 70 6c 65 45 76 65 6e 74 73 2c 20 MultipleEvents,
2700: 69 74 20 77 69 6c 6c 20 65 78 69 74 0d 0a 20 09 it will exit.. .
2710: 09 20 2a 20 63 6c 65 61 6e 6c 79 2e 0d 0a 20 09 . * cleanly... .
2720: 09 20 2a 2f 0d 0a 20 0d 0a 20 09 09 53 65 74 45 . */.. .. ..SetE
2730: 76 65 6e 74 28 70 69 70 65 50 74 72 2d 3e 73 74 vent(pipePtr->st
2740: 6f 70 57 72 69 74 65 72 29 3b 0d 0a 20 0d 0a 40 opWriter);.. ..@
2750: 40 20 2d 31 39 32 36 2c 32 31 20 2b 31 39 35 33 @ -1926,21 +1953
2760: 2c 33 38 20 40 40 0d 0a 20 09 09 20 20 20 20 20 ,38 @@.. ..
2770: 2a 20 75 6e 74 69 6c 20 61 20 62 65 74 74 65 72 * until a better
2780: 20 73 6f 6c 75 74 69 6f 6e 20 69 73 20 66 6f 75 solution is fou
2790: 6e 64 2e 0d 0a 20 09 09 20 20 20 20 20 2a 0d 0a nd... .. *..
27a0: 20 09 09 20 20 20 20 20 2a 20 4e 6f 74 65 20 74 .. * Note t
27b0: 68 61 74 20 77 65 20 6e 65 65 64 20 74 6f 20 67 hat we need to g
27c0: 75 61 72 64 20 61 67 61 69 6e 73 74 20 74 65 72 uard against ter
27d0: 6d 69 6e 61 74 69 6e 67 20 74 68 65 0d 0a 20 09 minating the.. .
27e0: 09 20 20 20 20 20 2a 20 74 68 72 65 61 64 20 77 . * thread w
27f0: 68 69 6c 65 20 69 74 20 69 73 20 69 6e 20 74 68 hile it is in th
2800: 65 20 6d 69 64 64 6c 65 20 6f 66 20 54 63 6c 5f e middle of Tcl_
2810: 54 68 72 65 61 64 41 6c 65 72 74 0d 0a 20 09 09 ThreadAlert.. ..
2820: 20 20 20 20 20 2a 20 62 65 63 61 75 73 65 20 69 * because i
2830: 74 20 77 6f 6e 27 74 20 62 65 20 61 62 6c 65 20 t won't be able
2840: 74 6f 20 72 65 6c 65 61 73 65 20 74 68 65 20 6e to release the n
2850: 6f 74 69 66 69 65 72 20 6c 6f 63 6b 2e 0d 0a 2b otifier lock...+
2860: 09 09 20 20 20 20 20 2a 0d 0a 2b 09 09 20 20 20 .. *..+..
2870: 20 20 2a 20 41 6c 73 6f 20 6e 6f 74 65 20 74 68 * Also note th
2880: 61 74 20 74 65 72 6d 69 6e 61 74 69 6e 67 20 74 at terminating t
2890: 68 72 65 61 64 73 20 64 75 72 69 6e 67 20 74 68 hreads during th
28a0: 65 69 72 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 eir initializati
28b0: 6f 6e 20 6f 72 20 74 65 61 72 64 6f 77 6e 20 70 on or teardown p
28c0: 68 61 73 65 0d 0a 2b 09 09 20 20 20 20 20 2a 20 hase..+.. *
28d0: 6d 61 79 20 72 65 73 75 6c 74 20 69 6e 20 6e 74 may result in nt
28e0: 64 6c 6c 2e 64 6c 6c 27 73 20 4c 6f 61 64 65 72 dll.dll's Loader
28f0: 4c 6f 63 6b 20 74 6f 20 72 65 6d 61 69 6e 20 6c Lock to remain l
2900: 6f 63 6b 65 64 20 69 6e 64 65 66 69 6e 69 74 65 ocked indefinite
2910: 6c 79 2e 0d 0a 2b 09 09 20 20 20 20 20 2a 20 54 ly...+.. * T
2920: 68 69 73 20 63 61 75 73 65 73 20 6e 74 64 6c 6c his causes ntdll
2930: 2e 64 6c 6c 27 73 20 4c 64 72 70 49 6e 69 74 69 .dll's LdrpIniti
2940: 61 6c 69 7a 65 54 68 72 65 61 64 28 29 20 74 6f alizeThread() to
2950: 20 64 65 61 64 6c 6f 63 6b 20 74 72 79 69 6e 67 deadlock trying
2960: 20 74 6f 20 61 63 71 75 69 72 65 20 4c 6f 61 64 to acquire Load
2970: 65 72 4c 6f 63 6b 2e 0d 0a 2b 09 09 20 20 20 20 erLock...+..
2980: 20 2a 20 4c 64 72 70 49 6e 69 74 69 61 6c 69 7a * LdrpInitializ
2990: 65 54 68 72 65 61 64 28 29 20 69 73 20 65 78 65 eThread() is exe
29a0: 63 75 74 65 64 20 77 69 74 68 69 6e 20 6e 65 77 cuted within new
29b0: 20 74 68 72 65 61 64 73 20 74 6f 20 70 65 72 66 threads to perf
29c0: 6f 72 6d 0d 0a 2b 09 09 20 20 20 20 20 2a 20 69 orm..+.. * i
29d0: 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 61 6e nitialization an
29e0: 64 20 74 6f 20 65 78 65 63 75 74 65 20 44 6c 6c d to execute Dll
29f0: 4d 61 69 6e 28 29 20 6f 66 20 61 6c 6c 20 6c 6f Main() of all lo
2a00: 61 64 65 64 20 64 6c 6c 73 2e 0d 0a 2b 09 09 20 aded dlls...+..
2a10: 20 20 20 20 2a 20 41 73 20 61 20 72 65 73 75 6c * As a resul
2a20: 74 2c 20 61 6c 6c 20 6e 65 77 20 74 68 72 65 61 t, all new threa
2a30: 64 73 20 61 72 65 20 64 65 61 64 6c 6f 63 6b 65 ds are deadlocke
2a40: 64 20 69 6e 20 74 68 65 69 72 20 69 6e 69 74 69 d in their initi
2a50: 61 6c 69 7a 61 74 69 6f 6e 20 70 68 61 73 65 20 alization phase
2a60: 61 6e 64 20 6e 65 76 65 72 20 65 78 65 63 75 74 and never execut
2a70: 65 2c 0d 0a 2b 09 09 20 20 20 20 20 2a 20 65 76 e,..+.. * ev
2a80: 65 6e 20 74 68 6f 75 67 68 20 43 72 65 61 74 65 en though Create
2a90: 54 68 72 65 61 64 28 29 20 72 65 70 6f 72 74 73 Thread() reports
2aa0: 20 73 75 63 63 65 73 73 66 75 6c 20 74 68 72 65 successful thre
2ab0: 61 64 20 63 72 65 61 74 69 6f 6e 2e 0d 0a 2b 09 ad creation...+.
2ac0: 09 20 20 20 20 20 2a 20 54 68 69 73 20 72 65 73 . * This res
2ad0: 75 6c 74 73 20 69 6e 20 61 20 76 65 72 79 20 77 ults in a very w
2ae0: 65 69 72 64 20 70 72 6f 63 65 73 73 2d 77 69 64 eird process-wid
2af0: 65 20 62 65 68 61 76 69 6f 72 2c 20 77 68 69 63 e behavior, whic
2b00: 68 20 69 73 20 65 78 74 72 65 6d 65 6c 79 20 68 h is extremely h
2b10: 61 72 64 20 74 6f 20 64 65 62 75 67 2e 0d 0a 2b ard to debug...+
2b20: 09 09 20 20 20 20 20 2a 20 0d 0a 2b 09 09 20 20 .. * ..+..
2b30: 20 20 20 2a 20 54 48 52 45 41 44 53 20 53 48 4f * THREADS SHO
2b40: 55 4c 44 20 4e 45 56 45 52 20 42 45 20 54 45 52 ULD NEVER BE TER
2b50: 4d 49 4e 41 54 45 44 2e 20 50 65 72 69 6f 64 2e MINATED. Period.
2b60: 0d 0a 2b 09 09 20 20 20 20 20 2a 20 0d 0a 2b 09 ..+.. * ..+.
2b70: 09 20 20 20 20 20 2a 20 42 75 74 20 66 6f 72 20 . * But for
2b80: 6e 6f 77 2c 20 63 68 65 63 6b 20 69 66 20 74 68 now, check if th
2b90: 72 65 61 64 20 69 73 20 65 78 69 74 69 6e 67 2c read is exiting,
2ba0: 20 61 6e 64 20 69 66 20 73 6f 2c 20 6c 65 74 20 and if so, let
2bb0: 69 74 20 64 69 65 20 70 65 61 63 65 66 75 6c 6c it die peacefull
2bc0: 79 2e 0d 0a 20 09 09 20 20 20 20 20 2a 2f 0d 0a y... .. */..
2bd0: 20 0d 0a 20 09 09 20 20 20 20 54 63 6c 5f 4d 75 .. .. Tcl_Mu
2be0: 74 65 78 4c 6f 63 6b 28 26 70 69 70 65 4d 75 74 texLock(&pipeMut
2bf0: 65 78 29 3b 0d 0a 2d 0d 0a 2d 09 09 20 20 20 20 ex);..-..-..
2c00: 2f 2a 20 42 55 47 3a 20 74 68 69 73 20 6c 65 61 /* BUG: this lea
2c10: 6b 73 20 6d 65 6d 6f 72 79 20 2a 2f 0d 0a 2d 09 ks memory */..-.
2c20: 09 20 20 20 20 54 65 72 6d 69 6e 61 74 65 54 68 . TerminateTh
2c30: 72 65 61 64 28 70 69 70 65 50 74 72 2d 3e 77 72 read(pipePtr->wr
2c40: 69 74 65 54 68 72 65 61 64 2c 20 30 29 3b 0d 0a iteThread, 0);..
2c50: 2b 09 09 20 20 20 20 69 66 20 28 20 70 69 70 65 +.. if ( pipe
2c60: 50 74 72 2d 3e 77 72 69 74 65 54 68 72 65 61 64 Ptr->writeThread
2c70: 45 78 69 74 69 6e 67 20 29 20 7b 0d 0a 2b 09 09 Exiting ) {..+..
2c80: 09 20 20 20 20 57 61 69 74 46 6f 72 53 69 6e 67 . WaitForSing
2c90: 6c 65 4f 62 6a 65 63 74 28 70 69 70 65 50 74 72 leObject(pipePtr
2ca0: 2d 3e 77 72 69 74 65 54 68 72 65 61 64 2c 20 49 ->writeThread, I
2cb0: 4e 46 49 4e 49 54 45 29 3b 0d 0a 2b 09 09 20 20 NFINITE);..+..
2cc0: 20 20 7d 20 65 6c 73 65 20 7b 0d 0a 2b 09 09 09 } else {..+...
2cd0: 20 20 20 20 2f 2a 20 42 55 47 3a 20 74 68 69 73 /* BUG: this
2ce0: 20 6c 65 61 6b 73 20 6d 65 6d 6f 72 79 20 2a 2f leaks memory */
2cf0: 0d 0a 2b 09 09 09 20 20 20 20 54 65 72 6d 69 6e ..+... Termin
2d00: 61 74 65 54 68 72 65 61 64 28 70 69 70 65 50 74 ateThread(pipePt
2d10: 72 2d 3e 77 72 69 74 65 54 68 72 65 61 64 2c 20 r->writeThread,
2d20: 30 29 3b 0d 0a 2b 09 09 20 20 20 20 7d 0d 0a 20 0);..+.. }..
2d30: 09 09 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 55 .. Tcl_MutexU
2d40: 6e 6c 6f 63 6b 28 26 70 69 70 65 4d 75 74 65 78 nlock(&pipeMutex
2d50: 29 3b 0d 0a 20 09 09 7d 0d 0a 20 09 20 20 20 20 );.. ..}.. .
2d60: 7d 0d 0a 20 0d 0a 20 09 20 20 20 20 43 6c 6f 73 }.. .. . Clos
2d70: 65 48 61 6e 64 6c 65 28 70 69 70 65 50 74 72 2d eHandle(pipePtr-
2d80: 3e 77 72 69 74 65 54 68 72 65 61 64 29 3b 0d 0a >writeThread);..
2d90: 2b 09 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c +. CloseHandl
2da0: 65 28 70 69 70 65 50 74 72 2d 3e 77 72 69 74 65 e(pipePtr->write
2db0: 54 68 72 65 61 64 49 6e 69 74 69 61 6c 69 7a 65 ThreadInitialize
2dc0: 64 29 3b 0d 0a 20 09 20 20 20 20 43 6c 6f 73 65 d);.. . Close
2dd0: 48 61 6e 64 6c 65 28 70 69 70 65 50 74 72 2d 3e Handle(pipePtr->
2de0: 77 72 69 74 61 62 6c 65 29 3b 0d 0a 20 09 20 20 writable);.. .
2df0: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 CloseHandle(pi
2e00: 70 65 50 74 72 2d 3e 73 74 61 72 74 57 72 69 74 pePtr->startWrit
2e10: 65 72 29 3b 0d 0a 20 09 20 20 20 20 43 6c 6f 73 er);.. . Clos
2e20: 65 48 61 6e 64 6c 65 28 70 69 70 65 50 74 72 2d eHandle(pipePtr-
2e30: 3e 73 74 6f 70 57 72 69 74 65 72 29 3b 0d 0a 20 >stopWriter);..
2e40: 09 20 20 20 20 70 69 70 65 50 74 72 2d 3e 77 72 . pipePtr->wr
2e50: 69 74 65 54 68 72 65 61 64 20 3d 20 4e 55 4c 4c iteThread = NULL
2e60: 3b 0d 0a 20 09 7d 0d 0a 40 40 20 2d 32 38 31 32 ;.. .}..@@ -2812
2e70: 2c 31 30 20 2b 32 38 35 36 2c 31 35 20 40 40 0d ,10 +2856,15 @@.
2e80: 0a 20 20 20 20 20 44 57 4f 52 44 20 63 6f 75 6e . DWORD coun
2e90: 74 2c 20 65 72 72 3b 0d 0a 20 20 20 20 20 69 6e t, err;.. in
2ea0: 74 20 64 6f 6e 65 20 3d 20 30 3b 0d 0a 20 20 20 t done = 0;..
2eb0: 20 20 48 41 4e 44 4c 45 20 77 45 76 65 6e 74 73 HANDLE wEvents
2ec0: 5b 32 5d 3b 0d 0a 20 20 20 20 20 44 57 4f 52 44 [2];.. DWORD
2ed0: 20 77 61 69 74 52 65 73 75 6c 74 3b 0d 0a 20 0d waitResult;.. .
2ee0: 0a 2b 20 20 20 20 2f 2a 0d 0a 2b 20 20 20 20 20 .+ /*..+
2ef0: 2a 20 4c 65 74 20 54 63 6c 70 43 72 65 61 74 65 * Let TclpCreate
2f00: 43 6f 6d 6d 61 6e 64 43 68 61 6e 6e 65 6c 28 29 CommandChannel()
2f10: 20 6b 6e 6f 77 20 74 68 61 74 20 74 68 69 73 20 know that this
2f20: 74 68 72 65 61 64 20 68 61 73 20 62 65 65 6e 20 thread has been
2f30: 69 6e 69 74 69 61 6c 69 7a 65 64 0d 0a 2b 20 20 initialized..+
2f40: 20 20 20 2a 2f 0d 0a 2b 20 20 20 20 53 65 74 45 */..+ SetE
2f50: 76 65 6e 74 28 69 6e 66 6f 50 74 72 2d 3e 72 65 vent(infoPtr->re
2f60: 61 64 54 68 72 65 61 64 49 6e 69 74 69 61 6c 69 adThreadInitiali
2f70: 7a 65 64 29 3b 0d 0a 2b 20 20 20 20 0d 0a 20 20 zed);..+ ..
2f80: 20 20 20 77 45 76 65 6e 74 73 5b 30 5d 20 3d 20 wEvents[0] =
2f90: 69 6e 66 6f 50 74 72 2d 3e 73 74 6f 70 52 65 61 infoPtr->stopRea
2fa0: 64 65 72 3b 0d 0a 20 20 20 20 20 77 45 76 65 6e der;.. wEven
2fb0: 74 73 5b 31 5d 20 3d 20 69 6e 66 6f 50 74 72 2d ts[1] = infoPtr-
2fc0: 3e 73 74 61 72 74 52 65 61 64 65 72 3b 0d 0a 20 >startReader;..
2fd0: 0d 0a 20 20 20 20 20 77 68 69 6c 65 20 28 21 64 .. while (!d
2fe0: 6f 6e 65 29 20 7b 0d 0a 20 09 2f 2a 0d 0a 40 40 one) {.. ./*..@@
2ff0: 20 2d 32 39 30 34 2c 31 30 20 2b 32 39 35 33 2c -2904,10 +2953,
3000: 31 38 20 40 40 0d 0a 20 09 20 20 20 20 54 63 6c 18 @@.. . Tcl
3010: 5f 54 68 72 65 61 64 41 6c 65 72 74 28 69 6e 66 _ThreadAlert(inf
3020: 6f 50 74 72 2d 3e 74 68 72 65 61 64 49 64 29 3b oPtr->threadId);
3030: 0d 0a 20 09 7d 0d 0a 20 09 54 63 6c 5f 4d 75 74 .. .}.. .Tcl_Mut
3040: 65 78 55 6e 6c 6f 63 6b 28 26 70 69 70 65 4d 75 exUnlock(&pipeMu
3050: 74 65 78 29 3b 0d 0a 20 20 20 20 20 7d 0d 0a 20 tex);.. }..
3060: 0d 0a 2b 20 20 20 20 2f 2a 0d 0a 2b 20 20 20 20 ..+ /*..+
3070: 20 2a 20 49 6e 66 6f 72 6d 20 50 69 70 65 43 6c * Inform PipeCl
3080: 6f 73 65 32 50 72 6f 63 28 29 20 74 68 61 74 20 ose2Proc() that
3090: 74 68 69 73 20 74 68 72 65 61 64 20 73 68 6f 75 this thread shou
30a0: 6c 64 20 6e 6f 74 20 62 65 20 74 65 72 6d 69 6e ld not be termin
30b0: 61 74 65 64 2c 20 73 69 6e 63 65 20 69 74 20 69 ated, since it i
30c0: 73 20 61 62 6f 75 74 20 74 6f 20 65 78 69 74 2e s about to exit.
30d0: 0d 0a 2b 20 20 20 20 20 2a 20 53 65 65 20 63 6f ..+ * See co
30e0: 6d 6d 65 6e 74 20 69 6e 20 50 69 70 65 43 6c 6f mment in PipeClo
30f0: 73 65 32 50 72 6f 63 28 29 20 66 6f 72 20 72 65 se2Proc() for re
3100: 61 73 6f 6e 73 2e 0d 0a 2b 20 20 20 20 2a 2f 0d asons...+ */.
3110: 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c .+ Tcl_MutexL
3120: 6f 63 6b 28 26 70 69 70 65 4d 75 74 65 78 29 3b ock(&pipeMutex);
3130: 0d 0a 2b 20 20 20 20 69 6e 66 6f 50 74 72 2d 3e ..+ infoPtr->
3140: 72 65 61 64 54 68 72 65 61 64 45 78 69 74 69 6e readThreadExitin
3150: 67 20 3d 20 54 52 55 45 3b 0d 0a 2b 20 20 20 20 g = TRUE;..+
3160: 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 Tcl_MutexUnlock(
3170: 26 70 69 70 65 4d 75 74 65 78 29 3b 0d 0a 2b 0d &pipeMutex);..+.
3180: 0a 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0d . return 0;.
3190: 0a 20 7d 0d 0a 20 0c 0d 0a 20 2f 2a 0d 0a 20 20 . }.. ... /*..
31a0: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *---------------
31b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
31c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
31d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
31e0: 2d 2d 2d 2d 2d 2d 2d 0d 0a 40 40 20 2d 32 39 33 -------..@@ -293
31f0: 36 2c 31 30 20 2b 32 39 39 33 2c 31 35 20 40 40 6,10 +2993,15 @@
3200: 0d 0a 20 20 20 20 20 63 68 61 72 20 2a 62 75 66 .. char *buf
3210: 3b 0d 0a 20 20 20 20 20 69 6e 74 20 64 6f 6e 65 ;.. int done
3220: 20 3d 20 30 3b 0d 0a 20 20 20 20 20 48 41 4e 44 = 0;.. HAND
3230: 4c 45 20 77 45 76 65 6e 74 73 5b 32 5d 3b 0d 0a LE wEvents[2];..
3240: 20 20 20 20 20 44 57 4f 52 44 20 77 61 69 74 52 DWORD waitR
3250: 65 73 75 6c 74 3b 0d 0a 20 0d 0a 2b 20 20 20 20 esult;.. ..+
3260: 2f 2a 0d 0a 2b 20 20 20 20 20 2a 20 4c 65 74 20 /*..+ * Let
3270: 54 63 6c 70 43 72 65 61 74 65 43 6f 6d 6d 61 6e TclpCreateComman
3280: 64 43 68 61 6e 6e 65 6c 28 29 20 6b 6e 6f 77 20 dChannel() know
3290: 74 68 61 74 20 74 68 69 73 20 74 68 72 65 61 64 that this thread
32a0: 20 68 61 73 20 62 65 65 6e 20 69 6e 69 74 69 61 has been initia
32b0: 6c 69 7a 65 64 0d 0a 2b 20 20 20 20 20 2a 2f 0d lized..+ */.
32c0: 0a 2b 20 20 20 20 53 65 74 45 76 65 6e 74 28 69 .+ SetEvent(i
32d0: 6e 66 6f 50 74 72 2d 3e 77 72 69 74 65 54 68 72 nfoPtr->writeThr
32e0: 65 61 64 49 6e 69 74 69 61 6c 69 7a 65 64 29 3b eadInitialized);
32f0: 0d 0a 2b 0d 0a 20 20 20 20 20 77 45 76 65 6e 74 ..+.. wEvent
3300: 73 5b 30 5d 20 3d 20 69 6e 66 6f 50 74 72 2d 3e s[0] = infoPtr->
3310: 73 74 6f 70 57 72 69 74 65 72 3b 0d 0a 20 20 20 stopWriter;..
3320: 20 20 77 45 76 65 6e 74 73 5b 31 5d 20 3d 20 69 wEvents[1] = i
3330: 6e 66 6f 50 74 72 2d 3e 73 74 61 72 74 57 72 69 nfoPtr->startWri
3340: 74 65 72 3b 0d 0a 20 0d 0a 20 20 20 20 20 77 68 ter;.. .. wh
3350: 69 6c 65 20 28 21 64 6f 6e 65 29 20 7b 0d 0a 20 ile (!done) {..
3360: 09 2f 2a 0d 0a 40 40 20 2d 33 30 30 32 2c 31 30 ./*..@@ -3002,10
3370: 20 2b 33 30 36 34 2c 31 38 20 40 40 0d 0a 20 09 +3064,18 @@.. .
3380: 20 20 20 20 54 63 6c 5f 54 68 72 65 61 64 41 6c Tcl_ThreadAl
3390: 65 72 74 28 69 6e 66 6f 50 74 72 2d 3e 74 68 72 ert(infoPtr->thr
33a0: 65 61 64 49 64 29 3b 0d 0a 20 09 7d 0d 0a 20 09 eadId);.. .}.. .
33b0: 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 Tcl_MutexUnlock(
33c0: 26 70 69 70 65 4d 75 74 65 78 29 3b 0d 0a 20 20 &pipeMutex);..
33d0: 20 20 20 7d 0d 0a 20 0d 0a 2b 20 20 20 20 2f 2a }.. ..+ /*
33e0: 0d 0a 2b 20 20 20 20 20 2a 20 49 6e 66 6f 72 6d ..+ * Inform
33f0: 20 50 69 70 65 43 6c 6f 73 65 32 50 72 6f 63 28 PipeClose2Proc(
3400: 29 20 74 68 61 74 20 74 68 69 73 20 74 68 72 65 ) that this thre
3410: 61 64 20 73 68 6f 75 6c 64 20 6e 6f 74 20 62 65 ad should not be
3420: 20 74 65 72 6d 69 6e 61 74 65 64 2c 20 73 69 6e terminated, sin
3430: 63 65 20 69 74 20 69 73 20 61 62 6f 75 74 20 74 ce it is about t
3440: 6f 20 65 78 69 74 2e 0d 0a 2b 20 20 20 20 20 2a o exit...+ *
3450: 20 53 65 65 20 63 6f 6d 6d 65 6e 74 20 69 6e 20 See comment in
3460: 50 69 70 65 43 6c 6f 73 65 32 50 72 6f 63 28 29 PipeClose2Proc()
3470: 20 66 6f 72 20 72 65 61 73 6f 6e 73 2e 0d 0a 2b for reasons...+
3480: 20 20 20 20 2a 2f 0d 0a 2b 20 20 20 20 54 63 6c */..+ Tcl
3490: 5f 4d 75 74 65 78 4c 6f 63 6b 28 26 70 69 70 65 _MutexLock(&pipe
34a0: 4d 75 74 65 78 29 3b 0d 0a 2b 20 20 20 20 69 6e Mutex);..+ in
34b0: 66 6f 50 74 72 2d 3e 77 72 69 74 65 54 68 72 65 foPtr->writeThre
34c0: 61 64 45 78 69 74 69 6e 67 20 3d 20 54 52 55 45 adExiting = TRUE
34d0: 3b 0d 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 ;..+ Tcl_Mute
34e0: 78 55 6e 6c 6f 63 6b 28 26 70 69 70 65 4d 75 74 xUnlock(&pipeMut
34f0: 65 78 29 3b 0d 0a 2b 0d 0a 20 20 20 20 20 72 65 ex);..+.. re
3500: 74 75 72 6e 20 30 3b 0d 0a 20 7d 0d 0a 20 0c 0d turn 0;.. }.. ..
3510: 0a 20 2f 2a 0d 0a 20 20 2a 2d 2d 2d 2d 2d 2d 2d . /*.. *-------
3520: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3530: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3540: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d ---------------.
3560: 0a 0d 0a 49 6e 64 65 78 3a 20 77 69 6e 2f 74 63 ...Index: win/tc
3570: 6c 57 69 6e 53 65 72 69 61 6c 2e 63 0d 0a 3d 3d lWinSerial.c..==
3580: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
3590: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
35a0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
35b0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
35c0: 0d 0a 2d 2d 2d 20 77 69 6e 2f 74 63 6c 57 69 6e ..--- win/tclWin
35d0: 53 65 72 69 61 6c 2e 63 0d 0a 2b 2b 2b 20 77 69 Serial.c..+++ wi
35e0: 6e 2f 74 63 6c 57 69 6e 53 65 72 69 61 6c 2e 63 n/tclWinSerial.c
35f0: 0d 0a 40 40 20 2d 39 32 2c 31 30 20 2b 39 32 2c ..@@ -92,10 +92,
3600: 31 32 20 40 40 0d 0a 20 09 09 09 09 20 2a 20 54 12 @@.. .... * T
3610: 68 69 73 20 76 61 6c 75 65 20 69 73 20 75 73 65 his value is use
3620: 64 20 62 79 20 74 68 65 20 72 65 61 64 65 72 2f d by the reader/
3630: 77 72 69 74 65 72 0d 0a 20 09 09 09 09 20 2a 20 writer.. .... *
3640: 74 68 72 65 61 64 73 2e 20 2a 2f 0d 0a 20 20 20 threads. */..
3650: 20 20 4f 56 45 52 4c 41 50 50 45 44 20 6f 73 52 OVERLAPPED osR
3660: 65 61 64 3b 09 09 2f 2a 20 4f 56 45 52 4c 41 50 ead;../* OVERLAP
3670: 50 45 44 20 73 74 72 75 63 74 75 72 65 20 66 6f PED structure fo
3680: 72 20 72 65 61 64 20 6f 70 65 72 61 74 69 6f 6e r read operation
3690: 73 2e 20 2a 2f 0d 0a 20 20 20 20 20 4f 56 45 52 s. */.. OVER
36a0: 4c 41 50 50 45 44 20 6f 73 57 72 69 74 65 3b 09 LAPPED osWrite;.
36b0: 09 2f 2a 20 4f 56 45 52 4c 41 50 50 45 44 20 73 ./* OVERLAPPED s
36c0: 74 72 75 63 74 75 72 65 20 66 6f 72 20 77 72 69 tructure for wri
36d0: 74 65 20 6f 70 65 72 61 74 69 6f 6e 73 20 2a 2f te operations */
36e0: 0d 0a 20 20 20 20 20 48 41 4e 44 4c 45 20 77 72 .. HANDLE wr
36f0: 69 74 65 54 68 72 65 61 64 3b 09 09 2f 2a 20 48 iteThread;../* H
3700: 61 6e 64 6c 65 20 74 6f 20 77 72 69 74 65 72 20 andle to writer
3710: 74 68 72 65 61 64 2e 20 2a 2f 0d 0a 2b 20 20 20 thread. */..+
3720: 20 48 41 4e 44 4c 45 20 77 72 69 74 65 54 68 72 HANDLE writeThr
3730: 65 61 64 49 6e 69 74 69 61 6c 69 7a 65 64 3b 09 eadInitialized;.
3740: 2f 2a 20 4d 61 6e 75 61 6c 2d 72 65 73 65 74 20 /* Manual-reset
3750: 65 76 65 6e 74 20 74 6f 20 73 69 67 6e 61 6c 20 event to signal
3760: 74 68 61 74 20 74 68 72 65 61 64 20 68 61 73 20 that thread has
3770: 62 65 65 6e 20 69 6e 69 74 69 61 6c 69 7a 65 64 been initialized
3780: 2e 20 2a 2f 0d 0a 2b 20 20 20 20 69 6e 74 20 77 . */..+ int w
3790: 72 69 74 65 54 68 72 65 61 64 45 78 69 74 69 6e riteThreadExitin
37a0: 67 3b 09 09 2f 2a 20 42 6f 6f 6c 65 61 6e 20 69 g;../* Boolean i
37b0: 6e 64 69 63 61 74 69 6e 67 20 74 68 61 74 20 74 ndicating that t
37c0: 68 72 65 61 64 20 69 73 20 65 78 69 74 69 6e 67 hread is exiting
37d0: 2e 20 2a 2f 0d 0a 20 20 20 20 20 43 52 49 54 49 . */.. CRITI
37e0: 43 41 4c 5f 53 45 43 54 49 4f 4e 20 63 73 57 72 CAL_SECTION csWr
37f0: 69 74 65 3b 09 2f 2a 20 57 72 69 74 65 72 20 74 ite;./* Writer t
3800: 68 72 65 61 64 20 73 79 6e 63 68 72 6f 6e 69 73 hread synchronis
3810: 61 74 69 6f 6e 2e 20 2a 2f 0d 0a 20 20 20 20 20 ation. */..
3820: 48 41 4e 44 4c 45 20 65 76 57 72 69 74 61 62 6c HANDLE evWritabl
3830: 65 3b 09 09 2f 2a 20 4d 61 6e 75 61 6c 2d 72 65 e;../* Manual-re
3840: 73 65 74 20 65 76 65 6e 74 20 74 6f 20 73 69 67 set event to sig
3850: 6e 61 6c 20 77 68 65 6e 20 74 68 65 0d 0a 20 09 nal when the.. .
3860: 09 09 09 20 2a 20 77 72 69 74 65 72 20 74 68 72 ... * writer thr
3870: 65 61 64 20 68 61 73 20 66 69 6e 69 73 68 65 64 ead has finished
3880: 20 77 61 69 74 69 6e 67 20 66 6f 72 20 74 68 65 waiting for the
3890: 0d 0a 20 09 09 09 09 20 2a 20 63 75 72 72 65 6e .. .... * curren
38a0: 74 20 62 75 66 66 65 72 20 74 6f 20 62 65 20 77 t buffer to be w
38b0: 72 69 74 74 65 6e 2e 20 2a 2f 0d 0a 20 20 20 20 ritten. */..
38c0: 20 48 41 4e 44 4c 45 20 65 76 53 74 61 72 74 57 HANDLE evStartW
38d0: 72 69 74 65 72 3b 09 2f 2a 20 41 75 74 6f 2d 72 riter;./* Auto-r
38e0: 65 73 65 74 20 65 76 65 6e 74 20 75 73 65 64 20 eset event used
38f0: 62 79 20 74 68 65 20 6d 61 69 6e 20 74 68 72 65 by the main thre
3900: 61 64 20 74 6f 0d 0a 40 40 20 2d 36 34 31 2c 32 ad to..@@ -641,2
3910: 32 20 2b 36 34 33 2c 33 38 20 40 40 0d 0a 20 09 2 +643,38 @@.. .
3920: 09 2f 2a 0d 0a 20 09 09 20 2a 20 46 6f 72 63 69 ./*.. .. * Forci
3930: 62 6c 79 20 74 65 72 6d 69 6e 61 74 65 20 74 68 bly terminate th
3940: 65 20 62 61 63 6b 67 72 6f 75 6e 64 20 74 68 72 e background thr
3950: 65 61 64 20 61 73 20 61 20 6c 61 73 74 20 72 65 ead as a last re
3960: 73 6f 72 74 2e 0d 0a 20 09 09 20 2a 20 4e 6f 74 sort... .. * Not
3970: 65 20 74 68 61 74 20 77 65 20 6e 65 65 64 20 74 e that we need t
3980: 6f 20 67 75 61 72 64 20 61 67 61 69 6e 73 74 20 o guard against
3990: 74 65 72 6d 69 6e 61 74 69 6e 67 20 74 68 65 20 terminating the
39a0: 74 68 72 65 61 64 0d 0a 20 09 09 20 2a 20 77 68 thread.. .. * wh
39b0: 69 6c 65 20 69 74 20 69 73 20 69 6e 20 74 68 65 ile it is in the
39c0: 20 6d 69 64 64 6c 65 20 6f 66 20 54 63 6c 5f 54 middle of Tcl_T
39d0: 68 72 65 61 64 41 6c 65 72 74 20 62 65 63 61 75 hreadAlert becau
39e0: 73 65 20 69 74 0d 0a 20 09 09 20 2a 20 77 6f 6e se it.. .. * won
39f0: 27 74 20 62 65 20 61 62 6c 65 20 74 6f 20 72 65 't be able to re
3a00: 6c 65 61 73 65 20 74 68 65 20 6e 6f 74 69 66 69 lease the notifi
3a10: 65 72 20 6c 6f 63 6b 2e 0d 0a 2b 09 09 20 2a 0d er lock...+.. *.
3a20: 0a 2b 09 09 20 2a 20 41 6c 73 6f 20 6e 6f 74 65 .+.. * Also note
3a30: 20 74 68 61 74 20 74 65 72 6d 69 6e 61 74 69 6e that terminatin
3a40: 67 20 74 68 72 65 61 64 73 20 64 75 72 69 6e 67 g threads during
3a50: 20 74 68 65 69 72 20 69 6e 69 74 69 61 6c 69 7a their initializ
3a60: 61 74 69 6f 6e 20 6f 72 20 74 65 61 72 64 6f 77 ation or teardow
3a70: 6e 20 70 68 61 73 65 0d 0a 2b 09 09 20 2a 20 6d n phase..+.. * m
3a80: 61 79 20 72 65 73 75 6c 74 20 69 6e 20 6e 74 64 ay result in ntd
3a90: 6c 6c 2e 64 6c 6c 27 73 20 4c 6f 61 64 65 72 4c ll.dll's LoaderL
3aa0: 6f 63 6b 20 74 6f 20 72 65 6d 61 69 6e 20 6c 6f ock to remain lo
3ab0: 63 6b 65 64 20 69 6e 64 65 66 69 6e 69 74 65 6c cked indefinitel
3ac0: 79 2e 0d 0a 2b 09 09 20 2a 20 54 68 69 73 20 63 y...+.. * This c
3ad0: 61 75 73 65 73 20 6e 74 64 6c 6c 2e 64 6c 6c 27 auses ntdll.dll'
3ae0: 73 20 4c 64 72 70 49 6e 69 74 69 61 6c 69 7a 65 s LdrpInitialize
3af0: 54 68 72 65 61 64 28 29 20 74 6f 20 64 65 61 64 Thread() to dead
3b00: 6c 6f 63 6b 20 74 72 79 69 6e 67 20 74 6f 20 61 lock trying to a
3b10: 63 71 75 69 72 65 20 4c 6f 61 64 65 72 4c 6f 63 cquire LoaderLoc
3b20: 6b 2e 0d 0a 2b 09 09 20 2a 20 4c 64 72 70 49 6e k...+.. * LdrpIn
3b30: 69 74 69 61 6c 69 7a 65 54 68 72 65 61 64 28 29 itializeThread()
3b40: 20 69 73 20 65 78 65 63 75 74 65 64 20 77 69 74 is executed wit
3b50: 68 69 6e 20 6e 65 77 20 74 68 72 65 61 64 73 20 hin new threads
3b60: 74 6f 20 70 65 72 66 6f 72 6d 0d 0a 2b 09 09 20 to perform..+..
3b70: 2a 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e * initialization
3b80: 20 61 6e 64 20 74 6f 20 65 78 65 63 75 74 65 20 and to execute
3b90: 44 6c 6c 4d 61 69 6e 28 29 20 6f 66 20 61 6c 6c DllMain() of all
3ba0: 20 6c 6f 61 64 65 64 20 64 6c 6c 73 2e 0d 0a 2b loaded dlls...+
3bb0: 09 09 20 2a 20 41 73 20 61 20 72 65 73 75 6c 74 .. * As a result
3bc0: 2c 20 61 6c 6c 20 6e 65 77 20 74 68 72 65 61 64 , all new thread
3bd0: 73 20 61 72 65 20 64 65 61 64 6c 6f 63 6b 65 64 s are deadlocked
3be0: 20 69 6e 20 74 68 65 69 72 20 69 6e 69 74 69 61 in their initia
3bf0: 6c 69 7a 61 74 69 6f 6e 20 70 68 61 73 65 20 61 lization phase a
3c00: 6e 64 20 6e 65 76 65 72 20 65 78 65 63 75 74 65 nd never execute
3c10: 2c 0d 0a 2b 09 09 20 2a 20 65 76 65 6e 20 74 68 ,..+.. * even th
3c20: 6f 75 67 68 20 43 72 65 61 74 65 54 68 72 65 61 ough CreateThrea
3c30: 64 28 29 20 72 65 70 6f 72 74 73 20 73 75 63 63 d() reports succ
3c40: 65 73 73 66 75 6c 20 74 68 72 65 61 64 20 63 72 essful thread cr
3c50: 65 61 74 69 6f 6e 2e 0d 0a 2b 09 09 20 2a 20 54 eation...+.. * T
3c60: 68 69 73 20 72 65 73 75 6c 74 73 20 69 6e 20 61 his results in a
3c70: 20 76 65 72 79 20 77 65 69 72 64 20 70 72 6f 63 very weird proc
3c80: 65 73 73 2d 77 69 64 65 20 62 65 68 61 76 69 6f ess-wide behavio
3c90: 72 2c 20 77 68 69 63 68 20 69 73 20 65 78 74 72 r, which is extr
3ca0: 65 6d 65 6c 79 20 68 61 72 64 20 74 6f 20 64 65 emely hard to de
3cb0: 62 75 67 2e 0d 0a 2b 09 09 20 2a 20 0d 0a 2b 09 bug...+.. * ..+.
3cc0: 09 20 2a 20 54 48 52 45 41 44 53 20 53 48 4f 55 . * THREADS SHOU
3cd0: 4c 44 20 4e 45 56 45 52 20 42 45 20 54 45 52 4d LD NEVER BE TERM
3ce0: 49 4e 41 54 45 44 2e 20 50 65 72 69 6f 64 2e 0d INATED. Period..
3cf0: 0a 2b 09 09 20 2a 20 0d 0a 2b 09 09 20 2a 20 42 .+.. * ..+.. * B
3d00: 75 74 20 66 6f 72 20 6e 6f 77 2c 20 63 68 65 63 ut for now, chec
3d10: 6b 20 69 66 20 74 68 72 65 61 64 20 69 73 20 65 k if thread is e
3d20: 78 69 74 69 6e 67 2c 20 61 6e 64 20 69 66 20 73 xiting, and if s
3d30: 6f 2c 20 6c 65 74 20 69 74 20 64 69 65 20 70 65 o, let it die pe
3d40: 61 63 65 66 75 6c 6c 79 2e 0d 0a 20 09 09 20 2a acefully... .. *
3d50: 2f 0d 0a 20 0d 0a 20 09 09 54 63 6c 5f 4d 75 74 /.. .. ..Tcl_Mut
3d60: 65 78 4c 6f 63 6b 28 26 73 65 72 69 61 6c 4d 75 exLock(&serialMu
3d70: 74 65 78 29 3b 0d 0a 2d 0d 0a 2d 09 09 2f 2a 20 tex);..-..-../*
3d80: 42 55 47 3a 20 74 68 69 73 20 6c 65 61 6b 73 20 BUG: this leaks
3d90: 6d 65 6d 6f 72 79 20 2a 2f 0d 0a 2d 09 09 54 65 memory */..-..Te
3da0: 72 6d 69 6e 61 74 65 54 68 72 65 61 64 28 73 65 rminateThread(se
3db0: 72 69 61 6c 50 74 72 2d 3e 77 72 69 74 65 54 68 rialPtr->writeTh
3dc0: 72 65 61 64 2c 20 30 29 3b 0d 0a 2d 0d 0a 2b 09 read, 0);..-..+.
3dd0: 09 69 66 20 28 20 73 65 72 69 61 6c 50 74 72 2d .if ( serialPtr-
3de0: 3e 77 72 69 74 65 54 68 72 65 61 64 45 78 69 74 >writeThreadExit
3df0: 69 6e 67 20 29 20 7b 0d 0a 2b 09 09 09 57 61 69 ing ) {..+...Wai
3e00: 74 46 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 63 74 tForSingleObject
3e10: 28 73 65 72 69 61 6c 50 74 72 2d 3e 77 72 69 74 (serialPtr->writ
3e20: 65 54 68 72 65 61 64 2c 20 49 4e 46 49 4e 49 54 eThread, INFINIT
3e30: 45 29 3b 0d 0a 2b 09 09 7d 20 65 6c 73 65 20 7b E);..+..} else {
3e40: 0d 0a 2b 09 09 09 2f 2a 20 42 55 47 3a 20 74 68 ..+.../* BUG: th
3e50: 69 73 20 6c 65 61 6b 73 20 6d 65 6d 6f 72 79 2e is leaks memory.
3e60: 20 2a 2f 0d 0a 2b 09 09 09 54 65 72 6d 69 6e 61 */..+...Termina
3e70: 74 65 54 68 72 65 61 64 28 73 65 72 69 61 6c 50 teThread(serialP
3e80: 74 72 2d 3e 77 72 69 74 65 54 68 72 65 61 64 2c tr->writeThread,
3e90: 20 30 29 3b 0d 0a 2b 09 09 7d 0d 0a 20 09 09 54 0);..+..}.. ..T
3ea0: 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 26 cl_MutexUnlock(&
3eb0: 73 65 72 69 61 6c 4d 75 74 65 78 29 3b 0d 0a 20 serialMutex);..
3ec0: 09 20 20 20 20 7d 0d 0a 20 09 7d 0d 0a 20 0d 0a . }.. .}.. ..
3ed0: 20 09 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 65 .CloseHandle(se
3ee0: 72 69 61 6c 50 74 72 2d 3e 77 72 69 74 65 54 68 rialPtr->writeTh
3ef0: 72 65 61 64 29 3b 0d 0a 2b 09 43 6c 6f 73 65 48 read);..+.CloseH
3f00: 61 6e 64 6c 65 28 73 65 72 69 61 6c 50 74 72 2d andle(serialPtr-
3f10: 3e 77 72 69 74 65 54 68 72 65 61 64 49 6e 69 74 >writeThreadInit
3f20: 69 61 6c 69 7a 65 64 29 3b 0d 0a 20 09 43 6c 6f ialized);.. .Clo
3f30: 73 65 48 61 6e 64 6c 65 28 73 65 72 69 61 6c 50 seHandle(serialP
3f40: 74 72 2d 3e 6f 73 57 72 69 74 65 2e 68 45 76 65 tr->osWrite.hEve
3f50: 6e 74 29 3b 0d 0a 20 09 43 6c 6f 73 65 48 61 6e nt);.. .CloseHan
3f60: 64 6c 65 28 73 65 72 69 61 6c 50 74 72 2d 3e 65 dle(serialPtr->e
3f70: 76 57 72 69 74 61 62 6c 65 29 3b 0d 0a 20 09 43 vWritable);.. .C
3f80: 6c 6f 73 65 48 61 6e 64 6c 65 28 73 65 72 69 61 loseHandle(seria
3f90: 6c 50 74 72 2d 3e 65 76 53 74 61 72 74 57 72 69 lPtr->evStartWri
3fa0: 74 65 72 29 3b 0d 0a 20 09 43 6c 6f 73 65 48 61 ter);.. .CloseHa
3fb0: 6e 64 6c 65 28 73 65 72 69 61 6c 50 74 72 2d 3e ndle(serialPtr->
3fc0: 65 76 53 74 6f 70 57 72 69 74 65 72 29 3b 0d 0a evStopWriter);..
3fd0: 20 09 73 65 72 69 61 6c 50 74 72 2d 3e 77 72 69 .serialPtr->wri
3fe0: 74 65 54 68 72 65 61 64 20 3d 20 4e 55 4c 4c 3b teThread = NULL;
3ff0: 0d 0a 40 40 20 2d 31 33 31 37 2c 31 30 20 2b 31 ..@@ -1317,10 +1
4000: 33 33 35 2c 31 35 20 40 40 0d 0a 20 20 20 20 20 335,15 @@..
4010: 44 57 4f 52 44 20 62 79 74 65 73 57 72 69 74 74 DWORD bytesWritt
4020: 65 6e 2c 20 74 6f 57 72 69 74 65 2c 20 77 61 69 en, toWrite, wai
4030: 74 52 65 73 75 6c 74 3b 0d 0a 20 20 20 20 20 63 tResult;.. c
4040: 68 61 72 20 2a 62 75 66 3b 0d 0a 20 20 20 20 20 har *buf;..
4050: 4f 56 45 52 4c 41 50 50 45 44 20 6d 79 57 72 69 OVERLAPPED myWri
4060: 74 65 3b 09 09 2f 2a 20 48 61 76 65 20 61 6e 20 te;../* Have an
4070: 6f 77 6e 20 4f 56 45 52 4c 41 50 50 45 44 20 69 own OVERLAPPED i
4080: 6e 20 74 68 69 73 20 74 68 72 65 61 64 2e 20 2a n this thread. *
4090: 2f 0d 0a 20 20 20 20 20 48 41 4e 44 4c 45 20 77 /.. HANDLE w
40a0: 45 76 65 6e 74 73 5b 32 5d 3b 0d 0a 20 0d 0a 2b Events[2];.. ..+
40b0: 20 20 20 20 2f 2a 0d 0a 2b 20 20 20 20 20 2a 20 /*..+ *
40c0: 4e 6f 74 69 66 79 20 54 63 6c 57 69 6e 4f 70 65 Notify TclWinOpe
40d0: 6e 53 65 72 69 61 6c 43 68 61 6e 6e 65 6c 28 29 nSerialChannel()
40e0: 20 74 68 61 74 20 74 68 69 73 20 74 68 72 65 61 that this threa
40f0: 64 20 69 73 20 69 6e 69 74 69 61 6c 69 7a 65 64 d is initialized
4100: 0d 0a 2b 20 20 20 20 20 2a 2f 0d 0a 2b 20 20 20 ..+ */..+
4110: 20 53 65 74 45 76 65 6e 74 28 69 6e 66 6f 50 74 SetEvent(infoPt
4120: 72 2d 3e 77 72 69 74 65 54 68 72 65 61 64 49 6e r->writeThreadIn
4130: 69 74 69 61 6c 69 7a 65 64 29 3b 0d 0a 2b 0d 0a itialized);..+..
4140: 20 20 20 20 20 2f 2a 0d 0a 20 20 20 20 20 20 2a /*.. *
4150: 20 54 68 65 20 73 74 6f 70 20 65 76 65 6e 74 20 The stop event
4160: 74 61 6b 65 73 20 70 72 65 63 65 64 65 6e 63 65 takes precedence
4170: 20 62 79 20 62 65 69 6e 67 20 66 69 72 73 74 20 by being first
4180: 69 6e 20 74 68 65 20 6c 69 73 74 2e 0d 0a 20 20 in the list...
4190: 20 20 20 20 2a 2f 0d 0a 20 0d 0a 20 20 20 20 20 */.. ..
41a0: 77 45 76 65 6e 74 73 5b 30 5d 20 3d 20 69 6e 66 wEvents[0] = inf
41b0: 6f 50 74 72 2d 3e 65 76 53 74 6f 70 57 72 69 74 oPtr->evStopWrit
41c0: 65 72 3b 0d 0a 40 40 20 2d 31 34 30 32 2c 31 30 er;..@@ -1402,10
41d0: 20 2b 31 34 32 35 2c 31 39 20 40 40 0d 0a 20 09 +1425,19 @@.. .
41e0: 20 20 20 20 54 63 6c 5f 54 68 72 65 61 64 41 6c Tcl_ThreadAl
41f0: 65 72 74 28 69 6e 66 6f 50 74 72 2d 3e 74 68 72 ert(infoPtr->thr
4200: 65 61 64 49 64 29 3b 0d 0a 20 09 7d 0d 0a 20 09 eadId);.. .}.. .
4210: 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 Tcl_MutexUnlock(
4220: 26 73 65 72 69 61 6c 4d 75 74 65 78 29 3b 0d 0a &serialMutex);..
4230: 20 20 20 20 20 7d 0d 0a 20 0d 0a 2b 0d 0a 2b 20 }.. ..+..+
4240: 20 20 20 2f 2a 0d 0a 2b 20 20 20 20 20 2a 20 49 /*..+ * I
4250: 6e 66 6f 72 6d 20 53 65 72 69 61 6c 43 6c 6f 73 nform SerialClos
4260: 65 50 72 6f 63 28 29 20 74 68 61 74 20 74 68 69 eProc() that thi
4270: 73 20 74 68 72 65 61 64 20 73 68 6f 75 6c 64 20 s thread should
4280: 6e 6f 74 20 62 65 20 74 65 72 6d 69 6e 61 74 65 not be terminate
4290: 64 2c 20 73 69 6e 63 65 20 69 74 20 69 73 20 61 d, since it is a
42a0: 62 6f 75 74 20 74 6f 20 65 78 69 74 2e 0d 0a 2b bout to exit...+
42b0: 20 20 20 20 20 2a 20 53 65 65 20 63 6f 6d 6d 65 * See comme
42c0: 6e 74 20 69 6e 20 53 65 72 69 61 6c 43 6c 6f 73 nt in SerialClos
42d0: 65 50 72 6f 63 28 29 20 66 6f 72 20 72 65 61 73 eProc() for reas
42e0: 6f 6e 73 2e 0d 0a 2b 20 20 20 20 2a 2f 0d 0a 2b ons...+ */..+
42f0: 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c 6f 63 Tcl_MutexLoc
4300: 6b 28 26 73 65 72 69 61 6c 4d 75 74 65 78 29 3b k(&serialMutex);
4310: 0d 0a 2b 20 20 20 20 69 6e 66 6f 50 74 72 2d 3e ..+ infoPtr->
4320: 77 72 69 74 65 54 68 72 65 61 64 45 78 69 74 69 writeThreadExiti
4330: 6e 67 20 3d 20 54 52 55 45 3b 0d 0a 2b 20 20 20 ng = TRUE;..+
4340: 20 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b Tcl_MutexUnlock
4350: 28 26 73 65 72 69 61 6c 4d 75 74 65 78 29 3b 0d (&serialMutex);.
4360: 0a 2b 0d 0a 20 20 20 20 20 72 65 74 75 72 6e 20 .+.. return
4370: 30 3b 0d 0a 20 7d 0d 0a 20 0c 0d 0a 20 2f 2a 0d 0;.. }.. ... /*.
4380: 0a 20 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d . *------------
4390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
43a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
43b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
43c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 40 40 20 2d ----------..@@ -
43d0: 31 35 32 34 2c 31 32 20 2b 31 35 35 36 2c 31 35 1524,12 +1556,15
43e0: 20 40 40 0d 0a 20 0d 0a 20 09 69 6e 66 6f 50 74 @@.. .. .infoPt
43f0: 72 2d 3e 6f 73 57 72 69 74 65 2e 68 45 76 65 6e r->osWrite.hEven
4400: 74 20 3d 20 43 72 65 61 74 65 45 76 65 6e 74 28 t = CreateEvent(
4410: 4e 55 4c 4c 2c 20 54 52 55 45 2c 20 46 41 4c 53 NULL, TRUE, FALS
4420: 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 20 09 69 6e 66 E, NULL);.. .inf
4430: 6f 50 74 72 2d 3e 65 76 57 72 69 74 61 62 6c 65 oPtr->evWritable
4440: 20 3d 20 43 72 65 61 74 65 45 76 65 6e 74 28 4e = CreateEvent(N
4450: 55 4c 4c 2c 20 54 52 55 45 2c 20 54 52 55 45 2c ULL, TRUE, TRUE,
4460: 20 4e 55 4c 4c 29 3b 0d 0a 20 09 69 6e 66 6f 50 NULL);.. .infoP
4470: 74 72 2d 3e 65 76 53 74 61 72 74 57 72 69 74 65 tr->evStartWrite
4480: 72 20 3d 20 43 72 65 61 74 65 45 76 65 6e 74 28 r = CreateEvent(
4490: 4e 55 4c 4c 2c 20 46 41 4c 53 45 2c 20 46 41 4c NULL, FALSE, FAL
44a0: 53 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 20 09 69 6e SE, NULL);.. .in
44b0: 66 6f 50 74 72 2d 3e 65 76 53 74 6f 70 57 72 69 foPtr->evStopWri
44c0: 74 65 72 20 3d 20 43 72 65 61 74 65 45 76 65 6e ter = CreateEven
44d0: 74 28 4e 55 4c 4c 2c 20 46 41 4c 53 45 2c 20 46 t(NULL, FALSE, F
44e0: 41 4c 53 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 2b 09 ALSE, NULL);..+.
44f0: 69 6e 66 6f 50 74 72 2d 3e 77 72 69 74 65 54 68 infoPtr->writeTh
4500: 72 65 61 64 49 6e 69 74 69 61 6c 69 7a 65 64 20 readInitialized
4510: 3d 20 43 72 65 61 74 65 45 76 65 6e 74 28 4e 55 = CreateEvent(NU
4520: 4c 4c 2c 20 54 52 55 45 2c 20 46 41 4c 53 45 2c LL, TRUE, FALSE,
4530: 20 4e 55 4c 4c 29 3b 0d 0a 2b 09 69 6e 66 6f 50 NULL);..+.infoP
4540: 74 72 2d 3e 77 72 69 74 65 54 68 72 65 61 64 45 tr->writeThreadE
4550: 78 69 74 69 6e 67 20 3d 20 46 41 4c 53 45 3b 0d xiting = FALSE;.
4560: 0a 20 09 69 6e 66 6f 50 74 72 2d 3e 77 72 69 74 . .infoPtr->writ
4570: 65 54 68 72 65 61 64 20 3d 20 43 72 65 61 74 65 eThread = Create
4580: 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 32 35 36 Thread(NULL, 256
4590: 2c 20 53 65 72 69 61 6c 57 72 69 74 65 72 54 68 , SerialWriterTh
45a0: 72 65 61 64 2c 0d 0a 20 09 09 69 6e 66 6f 50 74 read,.. ..infoPt
45b0: 72 2c 20 30 2c 20 26 69 64 29 3b 0d 0a 2b 09 57 r, 0, &id);..+.W
45c0: 61 69 74 46 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 aitForSingleObje
45d0: 63 74 28 69 6e 66 6f 50 74 72 2d 3e 77 72 69 74 ct(infoPtr->writ
45e0: 65 54 68 72 65 61 64 49 6e 69 74 69 61 6c 69 7a eThreadInitializ
45f0: 65 64 2c 20 49 4e 46 49 4e 49 54 45 29 3b 20 2f ed, INFINITE); /
4600: 2a 20 77 61 69 74 20 66 6f 72 20 74 68 72 65 61 * wait for threa
4610: 64 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 d to initialize
4620: 2a 2f 0d 0a 20 20 20 20 20 7d 0d 0a 20 0d 0a 20 */.. }.. ..
4630: 20 20 20 20 2f 2a 0d 0a 20 20 20 20 20 20 2a 20 /*.. *
4640: 46 69 6c 65 73 20 68 61 76 65 20 64 65 66 61 75 Files have defau
4650: 6c 74 20 74 72 61 6e 73 6c 61 74 69 6f 6e 20 6f lt translation o
4660: 66 20 41 55 54 4f 20 61 6e 64 20 5e 5a 20 65 6f f AUTO and ^Z eo
4670: 66 20 63 68 61 72 2c 20 77 68 69 63 68 20 6d 65 f char, which me
4680: 61 6e 73 0d 0a 20 20 20 20 20 20 2a 20 74 68 61 ans.. * tha
4690: 74 20 61 20 5e 5a 20 77 69 6c 6c 20 62 65 20 61 t a ^Z will be a
46a0: 63 63 65 70 74 65 64 20 61 73 20 45 4f 46 20 77 ccepted as EOF w
46b0: 68 65 6e 20 72 65 61 64 69 6e 67 2e 0d 0a 0d 0a hen reading.....