Tcl Source Code

Hex Artifact Content
Login

Artifact 15383b112e467cd9fa9bacc10ac96faaa7656703cb83f67f823d0bdb69c7c9ed:

Attachment "tclMutexTest.diff2" to ticket [893f8cc5db] added by chw 2025-10-06 18:35:12.
0000: 49 6e 64 65 78 3a 20 67 65 6e 65 72 69 63 2f 74  Index: generic/t
0010: 63 6c 4d 75 74 65 78 54 65 73 74 2e 63 0a 3d 3d  clMutexTest.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 3d 3d  ================
0060: 0a 2d 2d 2d 20 67 65 6e 65 72 69 63 2f 74 63 6c  .--- generic/tcl
0070: 4d 75 74 65 78 54 65 73 74 2e 63 0a 2b 2b 2b 20  MutexTest.c.+++ 
0080: 67 65 6e 65 72 69 63 2f 74 63 6c 4d 75 74 65 78  generic/tclMutex
0090: 54 65 73 74 2e 63 0a 40 40 20 2d 32 37 2c 31 30  Test.c.@@ -27,10
00a0: 20 2b 32 37 2c 31 32 20 40 40 0a 20 2f 2a 0a 20   +27,12 @@. /*. 
00b0: 20 2a 20 54 79 70 65 73 20 72 65 6c 61 74 65 64   * Types related
00c0: 20 74 6f 20 54 63 6c 5f 4d 75 74 65 78 20 74 65   to Tcl_Mutex te
00d0: 73 74 73 2e 0a 20 20 2a 2f 0a 20 0a 20 54 43 4c  sts..  */. . TCL
00e0: 5f 44 45 43 4c 41 52 45 5f 4d 55 54 45 58 28 74  _DECLARE_MUTEX(t
00f0: 65 73 74 43 6f 6e 74 65 78 74 4d 75 74 65 78 29  estContextMutex)
0100: 0a 2b 54 43 4c 5f 44 45 43 4c 41 52 45 5f 4d 55  .+TCL_DECLARE_MU
0110: 54 45 58 28 74 68 72 65 61 64 53 74 61 72 74 4d  TEX(threadStartM
0120: 75 74 65 78 29 0a 2b 73 74 61 74 69 63 20 54 63  utex).+static Tc
0130: 6c 5f 43 6f 6e 64 69 74 69 6f 6e 20 74 68 72 65  l_Condition thre
0140: 61 64 53 74 61 72 74 43 6f 6e 64 3b 0a 20 0a 20  adStartCond;. . 
0150: 73 74 61 74 69 63 20 69 6e 6c 69 6e 65 20 76 6f  static inline vo
0160: 69 64 0a 20 4c 6f 63 6b 54 65 73 74 43 6f 6e 74  id. LockTestCont
0170: 65 78 74 28 0a 20 20 20 20 20 69 6e 74 20 6e 75  ext(.     int nu
0180: 6d 52 65 63 75 72 73 69 6f 6e 73 29 0a 20 7b 0a  mRecursions). {.
0190: 40 40 20 2d 37 30 2c 31 30 20 2b 37 32 2c 31 31  @@ -70,10 +72,11
01a0: 20 40 40 0a 20 74 79 70 65 64 65 66 20 73 74 72   @@. typedef str
01b0: 75 63 74 20 7b 0a 20 20 20 20 20 69 6e 74 20 6e  uct {.     int n
01c0: 75 6d 54 68 72 65 61 64 73 3b 09 09 2f 2a 20 4e  umThreads;../* N
01d0: 75 6d 62 65 72 20 6f 66 20 74 68 72 65 61 64 73  umber of threads
01e0: 20 69 6e 20 74 65 73 74 20 72 75 6e 20 2a 2f 0a   in test run */.
01f0: 20 20 20 20 20 69 6e 74 20 6e 75 6d 52 65 63 75       int numRecu
0200: 72 73 69 6f 6e 73 3b 09 09 2f 2a 20 4e 75 6d 62  rsions;../* Numb
0210: 65 72 20 6f 66 20 6d 75 74 65 78 20 6c 6f 63 6b  er of mutex lock
0220: 20 72 65 63 75 72 73 69 6f 6e 73 20 2a 2f 0a 20   recursions */. 
0230: 20 20 20 20 69 6e 74 20 6e 75 6d 49 74 65 72 61      int numItera
0240: 74 69 6f 6e 73 3b 09 09 2f 2a 20 4e 75 6d 62 65  tions;../* Numbe
0250: 72 20 6f 66 20 74 69 6d 65 73 20 65 61 63 68 20  r of times each 
0260: 74 68 72 65 61 64 20 73 68 6f 75 6c 64 20 6c 6f  thread should lo
0270: 6f 70 20 2a 2f 0a 20 20 20 20 20 69 6e 74 20 79  op */.     int y
0280: 69 65 6c 64 3b 09 09 09 2f 2a 20 57 68 65 74 68  ield;.../* Wheth
0290: 65 72 20 74 68 72 65 61 64 73 20 73 68 6f 75 6c  er threads shoul
02a0: 64 20 79 69 65 6c 64 20 77 68 65 6e 20 6c 6f 6f  d yield when loo
02b0: 70 69 6e 67 20 2a 2f 0a 2b 20 20 20 20 69 6e 74  ping */.+    int
02c0: 20 72 75 6e 3b 09 09 09 2f 2a 20 57 68 65 74 68   run;.../* Wheth
02d0: 65 72 20 74 68 72 65 61 64 73 20 73 68 6f 75 6c  er threads shoul
02e0: 64 20 73 74 61 72 74 20 2a 2f 0a 20 20 20 20 20  d start */.     
02f0: 75 6e 69 6f 6e 20 7b 0a 20 09 54 63 6c 5f 57 69  union {. .Tcl_Wi
0300: 64 65 55 49 6e 74 20 63 6f 75 6e 74 65 72 3b 09  deUInt counter;.
0310: 09 2f 2a 20 55 73 65 64 20 69 6e 20 6c 6f 63 6b  ./* Used in lock
0320: 20 74 65 73 74 73 20 2a 2f 0a 20 09 50 72 6f 64   tests */. .Prod
0330: 75 63 65 72 43 6f 6e 73 75 6d 65 72 51 75 65 75  ucerConsumerQueu
0340: 65 20 71 75 65 75 65 3b 09 2f 2a 20 55 73 65 64  e queue;./* Used
0350: 20 69 6e 20 63 6f 6e 64 69 74 69 6f 6e 20 76 61   in condition va
0360: 72 69 61 62 6c 65 20 74 65 73 74 73 20 2a 2f 0a  riable tests */.
0370: 20 20 20 20 20 7d 20 75 3b 0a 20 7d 20 4d 75 74       } u;. } Mut
0380: 65 78 53 68 61 72 65 64 43 6f 6e 74 65 78 74 3b  exSharedContext;
0390: 0a 40 40 20 2d 38 37 2c 31 33 20 2b 39 30 2c 31  .@@ -87,13 +90,1
03a0: 30 20 40 40 0a 20 20 20 20 20 54 63 6c 5f 54 68  0 @@.     Tcl_Th
03b0: 72 65 61 64 49 64 20 74 68 72 65 61 64 49 64 3b  readId threadId;
03c0: 09 09 20 20 2f 2a 20 4f 6e 6c 79 20 61 63 63 65  ..  /* Only acce
03d0: 73 73 20 69 6e 20 63 72 65 61 74 6f 72 20 2a 2f  ss in creator */
03e0: 0a 20 20 20 20 20 54 63 6c 5f 57 69 64 65 55 49  .     Tcl_WideUI
03f0: 6e 74 20 6e 75 6d 4f 70 65 72 61 74 69 6f 6e 73  nt numOperations
0400: 3b 09 09 20 20 2f 2a 20 55 73 65 20 69 73 20 64  ;..  /* Use is d
0410: 65 70 65 6e 64 65 6e 74 20 6f 6e 20 74 68 65 20  ependent on the 
0420: 74 65 73 74 20 2a 2f 0a 20 20 20 20 20 54 63 6c  test */.     Tcl
0430: 5f 57 69 64 65 55 49 6e 74 20 74 69 6d 65 6f 75  _WideUInt timeou
0440: 74 73 3b 09 09 20 20 2f 2a 20 54 69 6d 65 6f 75  ts;..  /* Timeou
0450: 74 73 20 6f 6e 20 63 6f 6e 64 69 74 69 6f 6e 20  ts on condition 
0460: 76 61 72 69 61 62 6c 65 73 20 2a 2f 0a 20 7d 20  variables */. } 
0470: 4d 75 74 65 78 54 68 72 65 61 64 43 6f 6e 74 65  MutexThreadConte
0480: 78 74 3b 0a 20 0a 2d 2f 2a 20 55 73 65 64 20 74  xt;. .-/* Used t
0490: 6f 20 74 72 61 63 6b 20 68 6f 77 20 6d 61 6e 79  o track how many
04a0: 20 74 65 73 74 20 74 68 72 65 61 64 73 20 72 75   test threads ru
04b0: 6e 6e 69 6e 67 2e 20 41 6c 73 6f 20 75 73 65 64  nning. Also used
04c0: 20 61 73 20 74 72 69 67 67 65 72 20 2a 2f 0a 2d   as trigger */.-
04d0: 73 74 61 74 69 63 20 76 6f 6c 61 74 69 6c 65 20  static volatile 
04e0: 69 6e 74 20 6d 75 74 65 78 54 68 72 65 61 64 43  int mutexThreadC
04f0: 6f 75 6e 74 3b 0a 2d 0a 20 73 74 61 74 69 63 20  ount;.-. static 
0500: 54 63 6c 5f 54 68 72 65 61 64 43 72 65 61 74 65  Tcl_ThreadCreate
0510: 54 79 70 65 09 43 6f 75 6e 74 65 72 54 68 72 65  Type.CounterThre
0520: 61 64 50 72 6f 63 28 76 6f 69 64 20 2a 63 6c 69  adProc(void *cli
0530: 65 6e 74 44 61 74 61 29 3b 0a 20 73 74 61 74 69  entData);. stati
0540: 63 20 69 6e 74 09 09 09 54 65 73 74 4d 75 74 65  c int...TestMute
0550: 78 4c 6f 63 6b 28 54 63 6c 5f 49 6e 74 65 72 70  xLock(Tcl_Interp
0560: 20 2a 69 6e 74 65 72 70 2c 0a 20 09 09 09 09 20   *interp,. .... 
0570: 20 20 20 4d 75 74 65 78 53 68 61 72 65 64 43 6f     MutexSharedCo
0580: 6e 74 65 78 74 20 2a 63 6f 6e 74 65 78 74 50 74  ntext *contextPt
0590: 72 29 3b 0a 20 73 74 61 74 69 63 20 69 6e 74 09  r);. static int.
05a0: 09 09 54 65 73 74 43 6f 6e 64 69 74 69 6f 6e 56  ..TestConditionV
05b0: 61 72 69 61 62 6c 65 28 54 63 6c 5f 49 6e 74 65  ariable(Tcl_Inte
05c0: 72 70 20 2a 69 6e 74 65 72 70 2c 0a 20 09 09 09  rp *interp,. ...
05d0: 09 20 20 20 20 4d 75 74 65 78 53 68 61 72 65 64  .    MutexShared
05e0: 43 6f 6e 74 65 78 74 20 2a 63 6f 6e 74 65 78 74  Context *context
05f0: 50 74 72 29 3b 0a 40 40 20 2d 32 33 31 2c 31 32  Ptr);.@@ -231,12
0600: 20 2b 32 33 31 2c 31 37 20 40 40 0a 20 20 20 20   +231,17 @@.    
0610: 20 4d 75 74 65 78 53 68 61 72 65 64 43 6f 6e 74   MutexSharedCont
0620: 65 78 74 20 2a 63 6f 6e 74 65 78 74 50 74 72 29  ext *contextPtr)
0630: 0a 20 7b 0a 20 20 20 20 20 4d 75 74 65 78 54 68  . {.     MutexTh
0640: 72 65 61 64 43 6f 6e 74 65 78 74 20 2a 74 68 72  readContext *thr
0650: 65 61 64 43 6f 6e 74 65 78 74 73 50 74 72 20 3d  eadContextsPtr =
0660: 20 28 4d 75 74 65 78 54 68 72 65 61 64 43 6f 6e   (MutexThreadCon
0670: 74 65 78 74 20 2a 29 0a 20 09 20 20 20 20 54 63  text *). .    Tc
0680: 6c 5f 41 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 2a  l_Alloc(sizeof(*
0690: 74 68 72 65 61 64 43 6f 6e 74 65 78 74 73 50 74  threadContextsPt
06a0: 72 29 20 2a 20 63 6f 6e 74 65 78 74 50 74 72 2d  r) * contextPtr-
06b0: 3e 6e 75 6d 54 68 72 65 61 64 73 29 3b 0a 20 0a  >numThreads);. .
06c0: 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c 6f  +    Tcl_MutexLo
06d0: 63 6b 28 26 74 68 72 65 61 64 53 74 61 72 74 4d  ck(&threadStartM
06e0: 75 74 65 78 29 3b 0a 2b 20 20 20 20 2f 2a 20 49  utex);.+    /* I
06f0: 6e 66 6c 61 74 65 20 74 68 72 65 61 64 53 74 61  nflate threadSta
0700: 72 74 43 6f 6e 64 20 66 6f 72 20 6c 61 74 65 72  rtCond for later
0710: 20 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 54 69 6d   */.+    Tcl_Tim
0720: 65 20 6e 75 6c 6c 54 69 6d 65 20 3d 20 7b 20 30  e nullTime = { 0
0730: 2c 20 30 20 7d 3b 0a 2b 20 20 20 20 54 63 6c 5f  , 0 };.+    Tcl_
0740: 43 6f 6e 64 69 74 69 6f 6e 57 61 69 74 28 26 74  ConditionWait(&t
0750: 68 72 65 61 64 53 74 61 72 74 43 6f 6e 64 2c 20  hreadStartCond, 
0760: 26 74 68 72 65 61 64 53 74 61 72 74 4d 75 74 65  &threadStartMute
0770: 78 2c 20 26 6e 75 6c 6c 54 69 6d 65 29 3b 0a 2b  x, &nullTime);.+
0780: 0a 2b 20 20 20 20 63 6f 6e 74 65 78 74 50 74 72  .+    contextPtr
0790: 2d 3e 72 75 6e 20 3d 20 30 3b 0a 20 20 20 20 20  ->run = 0;.     
07a0: 63 6f 6e 74 65 78 74 50 74 72 2d 3e 75 2e 63 6f  contextPtr->u.co
07b0: 75 6e 74 65 72 20 3d 20 30 3b 0a 2d 20 20 20 20  unter = 0;.-    
07c0: 6d 75 74 65 78 54 68 72 65 61 64 43 6f 75 6e 74  mutexThreadCount
07d0: 20 3d 20 30 3b 0a 20 20 20 20 20 66 6f 72 20 28   = 0;.     for (
07e0: 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 63  int i = 0; i < c
07f0: 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 54 68  ontextPtr->numTh
0800: 72 65 61 64 73 3b 20 69 2b 2b 29 20 7b 0a 20 09  reads; i++) {. .
0810: 74 68 72 65 61 64 43 6f 6e 74 65 78 74 73 50 74  threadContextsPt
0820: 72 5b 69 5d 2e 73 68 61 72 65 64 43 6f 6e 74 65  r[i].sharedConte
0830: 78 74 50 74 72 20 3d 20 63 6f 6e 74 65 78 74 50  xtPtr = contextP
0840: 74 72 3b 0a 20 09 74 68 72 65 61 64 43 6f 6e 74  tr;. .threadCont
0850: 65 78 74 73 50 74 72 5b 69 5d 2e 6e 75 6d 4f 70  extsPtr[i].numOp
0860: 65 72 61 74 69 6f 6e 73 20 3d 20 30 3b 20 2f 2a  erations = 0; /*
0870: 20 49 6e 69 74 20 74 68 6f 75 67 68 20 6e 6f 74   Init though not
0880: 20 75 73 65 64 20 2a 2f 0a 20 0a 20 09 69 66 20   used */. . .if 
0890: 28 54 63 6c 5f 43 72 65 61 74 65 54 68 72 65 61  (Tcl_CreateThrea
08a0: 64 28 26 74 68 72 65 61 64 43 6f 6e 74 65 78 74  d(&threadContext
08b0: 73 50 74 72 5b 69 5d 2e 74 68 72 65 61 64 49 64  sPtr[i].threadId
08c0: 2c 0a 40 40 20 2d 32 34 33 2c 31 31 20 2b 32 34  ,.@@ -243,11 +24
08d0: 38 2c 31 35 20 40 40 0a 20 09 09 43 6f 75 6e 74  8,15 @@. ..Count
08e0: 65 72 54 68 72 65 61 64 50 72 6f 63 2c 20 26 74  erThreadProc, &t
08f0: 68 72 65 61 64 43 6f 6e 74 65 78 74 73 50 74 72  hreadContextsPtr
0900: 5b 69 5d 2c 0a 20 09 09 54 43 4c 5f 54 48 52 45  [i],. ..TCL_THRE
0910: 41 44 5f 53 54 41 43 4b 5f 44 45 46 41 55 4c 54  AD_STACK_DEFAULT
0920: 2c 20 54 43 4c 5f 54 48 52 45 41 44 5f 4a 4f 49  , TCL_THREAD_JOI
0930: 4e 41 42 4c 45 29 20 21 3d 20 54 43 4c 5f 4f 4b  NABLE) != TCL_OK
0940: 29 20 7b 0a 20 09 20 20 20 20 54 63 6c 5f 50 61  ) {. .    Tcl_Pa
0950: 6e 69 63 28 22 46 61 69 6c 65 64 20 74 6f 20 63  nic("Failed to c
0960: 72 65 61 74 65 20 25 64 27 74 68 20 74 68 72 65  reate %d'th thre
0970: 61 64 5c 6e 22 2c 20 69 29 3b 0a 20 09 7d 0a 20  ad\n", i);. .}. 
0980: 20 20 20 20 7d 0a 2d 20 20 20 20 6d 75 74 65 78      }.-    mutex
0990: 54 68 72 65 61 64 43 6f 75 6e 74 20 3d 20 63 6f  ThreadCount = co
09a0: 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 54 68 72  ntextPtr->numThr
09b0: 65 61 64 73 3b 20 2f 2a 20 57 69 6c 6c 20 66 69  eads; /* Will fi
09c0: 72 65 20 6f 66 66 20 61 6c 6c 20 74 65 73 74 20  re off all test 
09d0: 74 68 72 65 61 64 73 20 2a 2f 0a 2b 0a 2b 20 20  threads */.+.+  
09e0: 20 20 2f 2a 20 54 72 69 67 67 65 72 20 73 74 61    /* Trigger sta
09f0: 72 74 20 73 69 67 6e 61 6c 20 2a 2f 0a 2b 20 20  rt signal */.+  
0a00: 20 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 72 75    contextPtr->ru
0a10: 6e 20 3d 20 31 3b 0a 2b 20 20 20 20 54 63 6c 5f  n = 1;.+    Tcl_
0a20: 43 6f 6e 64 69 74 69 6f 6e 4e 6f 74 69 66 79 28  ConditionNotify(
0a30: 26 74 68 72 65 61 64 53 74 61 72 74 43 6f 6e 64  &threadStartCond
0a40: 29 3b 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65  );.+    Tcl_Mute
0a50: 78 55 6e 6c 6f 63 6b 28 26 74 68 72 65 61 64 53  xUnlock(&threadS
0a60: 74 61 72 74 4d 75 74 65 78 29 3b 0a 20 0a 20 20  tartMutex);. .  
0a70: 20 20 20 2f 2a 20 57 61 69 74 20 66 6f 72 20 61     /* Wait for a
0a80: 6c 6c 20 74 68 72 65 61 64 73 20 2a 2f 0a 20 20  ll threads */.  
0a90: 20 20 20 66 6f 72 20 28 69 6e 74 20 69 20 3d 20     for (int i = 
0aa0: 30 3b 20 69 20 3c 20 63 6f 6e 74 65 78 74 50 74  0; i < contextPt
0ab0: 72 2d 3e 6e 75 6d 54 68 72 65 61 64 73 3b 20 69  r->numThreads; i
0ac0: 2b 2b 29 20 7b 0a 20 09 69 6e 74 20 74 68 72 65  ++) {. .int thre
0ad0: 61 64 52 65 73 75 6c 74 3b 0a 20 09 54 63 6c 5f  adResult;. .Tcl_
0ae0: 4a 6f 69 6e 54 68 72 65 61 64 28 74 68 72 65 61  JoinThread(threa
0af0: 64 43 6f 6e 74 65 78 74 73 50 74 72 5b 69 5d 2e  dContextsPtr[i].
0b00: 74 68 72 65 61 64 49 64 2c 20 26 74 68 72 65 61  threadId, &threa
0b10: 64 52 65 73 75 6c 74 29 3b 0a 40 40 20 2d 32 37  dResult);.@@ -27
0b20: 39 2c 31 34 20 2b 32 38 38 2c 31 36 20 40 40 0a  9,14 +288,16 @@.
0b30: 20 20 20 20 20 76 6f 69 64 20 2a 63 6c 69 65 6e       void *clien
0b40: 74 44 61 74 61 29 0a 20 7b 0a 20 20 20 20 20 4d  tData). {.     M
0b50: 75 74 65 78 54 68 72 65 61 64 43 6f 6e 74 65 78  utexThreadContex
0b60: 74 20 2a 74 68 72 65 61 64 43 6f 6e 74 65 78 74  t *threadContext
0b70: 50 74 72 20 3d 20 28 4d 75 74 65 78 54 68 72 65  Ptr = (MutexThre
0b80: 61 64 43 6f 6e 74 65 78 74 20 2a 29 63 6c 69 65  adContext *)clie
0b90: 6e 74 44 61 74 61 3b 0a 20 20 20 20 20 4d 75 74  ntData;.     Mut
0ba0: 65 78 53 68 61 72 65 64 43 6f 6e 74 65 78 74 20  exSharedContext 
0bb0: 2a 63 6f 6e 74 65 78 74 50 74 72 20 3d 20 74 68  *contextPtr = th
0bc0: 72 65 61 64 43 6f 6e 74 65 78 74 50 74 72 2d 3e  readContextPtr->
0bd0: 73 68 61 72 65 64 43 6f 6e 74 65 78 74 50 74 72  sharedContextPtr
0be0: 3b 0a 20 0a 2d 20 20 20 20 2f 2a 20 53 70 69 6e  ;. .-    /* Spin
0bf0: 20 77 61 69 74 20 75 6e 74 69 6c 20 67 69 76 65   wait until give
0c00: 6e 20 74 68 65 20 72 75 6e 20 73 69 67 6e 61 6c  n the run signal
0c10: 20 2a 2f 0a 2d 20 20 20 20 77 68 69 6c 65 20 28   */.-    while (
0c20: 6d 75 74 65 78 54 68 72 65 61 64 43 6f 75 6e 74  mutexThreadCount
0c30: 20 3c 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e   < contextPtr->n
0c40: 75 6d 54 68 72 65 61 64 73 29 20 7b 0a 2d 09 59  umThreads) {.-.Y
0c50: 69 65 6c 64 54 6f 4f 74 68 65 72 54 68 72 65 61  ieldToOtherThrea
0c60: 64 73 28 29 3b 0a 2b 20 20 20 20 2f 2a 20 57 61  ds();.+    /* Wa
0c70: 69 74 20 66 6f 72 20 73 74 61 72 74 20 73 69 67  it for start sig
0c80: 6e 61 6c 20 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f  nal */.+    Tcl_
0c90: 4d 75 74 65 78 4c 6f 63 6b 28 26 74 68 72 65 61  MutexLock(&threa
0ca0: 64 53 74 61 72 74 4d 75 74 65 78 29 3b 0a 2b 20  dStartMutex);.+ 
0cb0: 20 20 20 77 68 69 6c 65 20 28 21 74 68 72 65 61     while (!threa
0cc0: 64 43 6f 6e 74 65 78 74 50 74 72 2d 3e 72 75 6e  dContextPtr->run
0cd0: 29 20 7b 0a 2b 09 54 63 6c 5f 43 6f 6e 64 69 74  ) {.+.Tcl_Condit
0ce0: 69 6f 6e 57 61 69 74 28 26 74 68 72 65 61 64 53  ionWait(&threadS
0cf0: 74 61 72 74 43 6f 6e 64 2c 20 26 74 68 72 65 61  tartCond, &threa
0d00: 64 53 74 61 72 74 4d 75 74 65 78 2c 20 4e 55 4c  dStartMutex, NUL
0d10: 4c 29 3b 0a 20 20 20 20 20 7d 0a 2b 20 20 20 20  L);.     }.+    
0d20: 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28  Tcl_MutexUnlock(
0d30: 26 74 68 72 65 61 64 53 74 61 72 74 4d 75 74 65  &threadStartMute
0d40: 78 29 3b 0a 20 0a 20 20 20 20 20 66 6f 72 20 28  x);. .     for (
0d50: 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 63  int i = 0; i < c
0d60: 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 49 74  ontextPtr->numIt
0d70: 65 72 61 74 69 6f 6e 73 3b 20 69 2b 2b 29 20 7b  erations; i++) {
0d80: 0a 20 09 4c 6f 63 6b 54 65 73 74 43 6f 6e 74 65  . .LockTestConte
0d90: 78 74 28 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e  xt(contextPtr->n
0da0: 75 6d 52 65 63 75 72 73 69 6f 6e 73 29 3b 0a 20  umRecursions);. 
0db0: 09 54 63 6c 5f 57 69 64 65 55 49 6e 74 20 74 65  .Tcl_WideUInt te
0dc0: 6d 70 20 3d 20 63 6f 6e 74 65 78 74 50 74 72 2d  mp = contextPtr-
0dd0: 3e 75 2e 63 6f 75 6e 74 65 72 3b 0a 20 09 69 66  >u.counter;. .if
0de0: 20 28 63 6f 6e 74 65 78 74 50 74 72 2d 3e 79 69   (contextPtr->yi
0df0: 65 6c 64 29 20 7b 0a 40 40 20 2d 33 32 37 2c 31  eld) {.@@ -327,1
0e00: 30 20 2b 33 33 38 2c 31 31 20 40 40 0a 20 09 72  0 +338,11 @@. .r
0e10: 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b  eturn TCL_ERROR;
0e20: 0a 20 20 20 20 20 7d 0a 20 20 20 20 20 69 6e 74  .     }.     int
0e30: 20 6e 75 6d 50 72 6f 64 75 63 65 72 73 20 3d 20   numProducers = 
0e40: 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 54  contextPtr->numT
0e50: 68 72 65 61 64 73 20 2f 20 32 3b 0a 20 20 20 20  hreads / 2;.    
0e60: 20 69 6e 74 20 6e 75 6d 43 6f 6e 73 75 6d 65 72   int numConsumer
0e70: 73 20 3d 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e  s = contextPtr->
0e80: 6e 75 6d 54 68 72 65 61 64 73 20 2d 20 6e 75 6d  numThreads - num
0e90: 50 72 6f 64 75 63 65 72 73 3b 0a 20 0a 2b 20 20  Producers;. .+  
0ea0: 20 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 72 75    contextPtr->ru
0eb0: 6e 20 3d 20 30 3b 0a 20 20 20 20 20 63 6f 6e 74  n = 0;.     cont
0ec0: 65 78 74 50 74 72 2d 3e 75 2e 71 75 65 75 65 2e  extPtr->u.queue.
0ed0: 63 61 6e 44 65 71 75 65 75 65 20 3d 20 4e 55 4c  canDequeue = NUL
0ee0: 4c 3b 0a 20 20 20 20 20 63 6f 6e 74 65 78 74 50  L;.     contextP
0ef0: 74 72 2d 3e 75 2e 71 75 65 75 65 2e 63 61 6e 45  tr->u.queue.canE
0f00: 6e 71 75 65 75 65 20 3d 20 4e 55 4c 4c 3b 0a 20  nqueue = NULL;. 
0f10: 0a 20 20 20 20 20 2f 2a 0a 20 20 20 20 20 20 2a  .     /*.      *
0f20: 20 61 76 61 69 6c 61 62 6c 65 20 74 72 61 63 6b   available track
0f30: 73 20 68 6f 77 20 6d 61 6e 79 20 65 6c 65 6d 65  s how many eleme
0f40: 6e 74 73 20 69 6e 20 74 68 65 20 76 69 72 74 75  nts in the virtu
0f50: 61 6c 20 71 75 65 75 65 0a 40 40 20 2d 33 34 34  al queue.@@ -344
0f60: 2c 31 31 20 2b 33 35 36 2c 31 34 20 40 40 0a 20  ,11 +356,14 @@. 
0f70: 20 20 20 20 4d 75 74 65 78 54 68 72 65 61 64 43      MutexThreadC
0f80: 6f 6e 74 65 78 74 20 2a 63 6f 6e 73 75 6d 65 72  ontext *consumer
0f90: 43 6f 6e 74 65 78 74 73 50 74 72 20 3d 20 28 4d  ContextsPtr = (M
0fa0: 75 74 65 78 54 68 72 65 61 64 43 6f 6e 74 65 78  utexThreadContex
0fb0: 74 20 2a 29 54 63 6c 5f 41 6c 6c 6f 63 28 0a 20  t *)Tcl_Alloc(. 
0fc0: 09 20 20 20 20 73 69 7a 65 6f 66 28 2a 63 6f 6e  .    sizeof(*con
0fd0: 73 75 6d 65 72 43 6f 6e 74 65 78 74 73 50 74 72  sumerContextsPtr
0fe0: 29 20 2a 20 6e 75 6d 43 6f 6e 73 75 6d 65 72 73  ) * numConsumers
0ff0: 29 3b 0a 20 20 20 20 20 4d 75 74 65 78 54 68 72  );.     MutexThr
1000: 65 61 64 43 6f 6e 74 65 78 74 20 2a 70 72 6f 64  eadContext *prod
1010: 75 63 65 72 43 6f 6e 74 65 78 74 73 50 74 72 20  ucerContextsPtr 
1020: 3d 20 28 4d 75 74 65 78 54 68 72 65 61 64 43 6f  = (MutexThreadCo
1030: 6e 74 65 78 74 20 2a 29 54 63 6c 5f 41 6c 6c 6f  ntext *)Tcl_Allo
1040: 63 28 0a 20 09 20 20 20 20 73 69 7a 65 6f 66 28  c(. .    sizeof(
1050: 2a 70 72 6f 64 75 63 65 72 43 6f 6e 74 65 78 74  *producerContext
1060: 73 50 74 72 29 20 2a 20 6e 75 6d 50 72 6f 64 75  sPtr) * numProdu
1070: 63 65 72 73 29 3b 0a 20 0a 2d 20 20 20 20 6d 75  cers);. .-    mu
1080: 74 65 78 54 68 72 65 61 64 43 6f 75 6e 74 20 3d  texThreadCount =
1090: 20 30 3b 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74   0;.+    Tcl_Mut
10a0: 65 78 4c 6f 63 6b 28 26 74 68 72 65 61 64 53 74  exLock(&threadSt
10b0: 61 72 74 4d 75 74 65 78 29 3b 0a 2b 20 20 20 20  artMutex);.+    
10c0: 2f 2a 20 49 6e 66 6c 61 74 65 20 74 68 72 65 61  /* Inflate threa
10d0: 64 53 74 61 72 74 43 6f 6e 64 20 66 6f 72 20 6c  dStartCond for l
10e0: 61 74 65 72 20 2a 2f 0a 2b 20 20 20 20 54 63 6c  ater */.+    Tcl
10f0: 5f 54 69 6d 65 20 6e 75 6c 6c 54 69 6d 65 20 3d  _Time nullTime =
1100: 20 7b 20 30 2c 20 30 20 7d 3b 0a 2b 20 20 20 20   { 0, 0 };.+    
1110: 54 63 6c 5f 43 6f 6e 64 69 74 69 6f 6e 57 61 69  Tcl_ConditionWai
1120: 74 28 26 74 68 72 65 61 64 53 74 61 72 74 43 6f  t(&threadStartCo
1130: 6e 64 2c 20 26 74 68 72 65 61 64 53 74 61 72 74  nd, &threadStart
1140: 4d 75 74 65 78 2c 20 26 6e 75 6c 6c 54 69 6d 65  Mutex, &nullTime
1150: 29 3b 0a 20 0a 20 20 20 20 20 66 6f 72 20 28 69  );. .     for (i
1160: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 6e 75  nt i = 0; i < nu
1170: 6d 43 6f 6e 73 75 6d 65 72 73 3b 20 69 2b 2b 29  mConsumers; i++)
1180: 20 7b 0a 20 09 63 6f 6e 73 75 6d 65 72 43 6f 6e   {. .consumerCon
1190: 74 65 78 74 73 50 74 72 5b 69 5d 2e 73 68 61 72  textsPtr[i].shar
11a0: 65 64 43 6f 6e 74 65 78 74 50 74 72 20 3d 20 63  edContextPtr = c
11b0: 6f 6e 74 65 78 74 50 74 72 3b 0a 20 09 63 6f 6e  ontextPtr;. .con
11c0: 73 75 6d 65 72 43 6f 6e 74 65 78 74 73 50 74 72  sumerContextsPtr
11d0: 5b 69 5d 2e 6e 75 6d 4f 70 65 72 61 74 69 6f 6e  [i].numOperation
11e0: 73 20 3d 20 30 3b 0a 20 09 63 6f 6e 73 75 6d 65  s = 0;. .consume
11f0: 72 43 6f 6e 74 65 78 74 73 50 74 72 5b 69 5d 2e  rContextsPtr[i].
1200: 74 69 6d 65 6f 75 74 73 20 3d 20 30 3b 0a 40 40  timeouts = 0;.@@
1210: 20 2d 33 37 30 2c 31 31 20 2b 33 38 35 2c 31 34   -370,11 +385,14
1220: 20 40 40 0a 20 09 09 54 43 4c 5f 54 48 52 45 41   @@. ..TCL_THREA
1230: 44 5f 53 54 41 43 4b 5f 44 45 46 41 55 4c 54 2c  D_STACK_DEFAULT,
1240: 20 54 43 4c 5f 54 48 52 45 41 44 5f 4a 4f 49 4e   TCL_THREAD_JOIN
1250: 41 42 4c 45 29 20 21 3d 20 54 43 4c 5f 4f 4b 29  ABLE) != TCL_OK)
1260: 20 7b 0a 20 09 20 20 20 20 54 63 6c 5f 50 61 6e   {. .    Tcl_Pan
1270: 69 63 28 22 46 61 69 6c 65 64 20 74 6f 20 63 72  ic("Failed to cr
1280: 65 61 74 65 20 25 64 27 74 68 20 74 68 72 65 61  eate %d'th threa
1290: 64 5c 6e 22 2c 20 28 69 6e 74 29 20 69 29 3b 0a  d\n", (int) i);.
12a0: 20 09 7d 0a 20 20 20 20 20 7d 0a 20 0a 2d 20 20   .}.     }. .-  
12b0: 20 20 6d 75 74 65 78 54 68 72 65 61 64 43 6f 75    mutexThreadCou
12c0: 6e 74 20 3d 20 63 6f 6e 74 65 78 74 50 74 72 2d  nt = contextPtr-
12d0: 3e 6e 75 6d 54 68 72 65 61 64 73 3b 20 2f 2a 20  >numThreads; /* 
12e0: 57 69 6c 6c 20 74 72 69 67 67 65 72 20 61 6c 6c  Will trigger all
12f0: 20 74 68 72 65 61 64 73 20 2a 2f 0a 2b 20 20 20   threads */.+   
1300: 20 2f 2a 20 54 72 69 67 67 65 72 20 73 74 61 72   /* Trigger star
1310: 74 20 73 69 67 6e 61 6c 20 2a 2f 0a 2b 20 20 20  t signal */.+   
1320: 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 72 75 6e   contextPtr->run
1330: 20 3d 20 31 3b 0a 2b 20 20 20 20 54 63 6c 5f 43   = 1;.+    Tcl_C
1340: 6f 6e 64 69 74 69 6f 6e 4e 6f 74 69 66 79 28 26  onditionNotify(&
1350: 74 68 72 65 61 64 53 74 61 72 74 43 6f 6e 64 29  threadStartCond)
1360: 3b 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 78  ;.+    Tcl_Mutex
1370: 55 6e 6c 6f 63 6b 28 26 74 68 72 65 61 64 53 74  Unlock(&threadSt
1380: 61 72 74 4d 75 74 65 78 29 3b 0a 20 0a 20 20 20  artMutex);. .   
1390: 20 20 2f 2a 20 50 72 6f 64 75 63 65 72 20 74 6f    /* Producer to
13a0: 74 61 6c 2c 20 74 68 72 65 61 64 2c 20 74 69 6d  tal, thread, tim
13b0: 65 6f 75 74 73 2c 20 43 6f 6e 73 75 6d 65 72 20  eouts, Consumer 
13c0: 74 6f 74 61 6c 2c 20 74 68 72 65 61 64 2c 20 74  total, thread, t
13d0: 69 6d 65 6f 75 74 73 20 2a 2f 0a 20 20 20 20 20  imeouts */.     
13e0: 54 63 6c 5f 4f 62 6a 20 2a 72 65 73 75 6c 74 73  Tcl_Obj *results
13f0: 5b 36 5d 3b 0a 20 20 20 20 20 72 65 73 75 6c 74  [6];.     result
1400: 73 5b 31 5d 20 3d 20 54 63 6c 5f 4e 65 77 4c 69  s[1] = Tcl_NewLi
1410: 73 74 4f 62 6a 28 6e 75 6d 50 72 6f 64 75 63 65  stObj(numProduce
1420: 72 73 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20  rs, NULL);.     
1430: 72 65 73 75 6c 74 73 5b 34 5d 20 3d 20 54 63 6c  results[4] = Tcl
1440: 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 6e 75 6d 43  _NewListObj(numC
1450: 6f 6e 73 75 6d 65 72 73 2c 20 4e 55 4c 4c 29 3b  onsumers, NULL);
1460: 0a 40 40 20 2d 34 33 39 2c 31 34 20 2b 34 35 37  .@@ -439,14 +457
1470: 2c 31 36 20 40 40 0a 20 0a 20 20 20 20 20 2f 2a  ,16 @@. .     /*
1480: 20 4c 69 6d 69 74 20 6f 6e 20 74 6f 74 61 6c 20   Limit on total 
1490: 6e 75 6d 62 65 72 20 6f 66 20 6f 70 65 72 61 74  number of operat
14a0: 69 6f 6e 73 20 61 63 72 6f 73 73 20 61 6c 6c 20  ions across all 
14b0: 74 68 72 65 61 64 73 20 2a 2f 0a 20 20 20 20 20  threads */.     
14c0: 54 63 6c 5f 57 69 64 65 55 49 6e 74 20 6c 69 6d  Tcl_WideUInt lim
14d0: 69 74 3b 0a 20 20 20 20 20 6c 69 6d 69 74 20 3d  it;.     limit =
14e0: 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d   contextPtr->num
14f0: 54 68 72 65 61 64 73 20 2a 20 28 54 63 6c 5f 57  Threads * (Tcl_W
1500: 69 64 65 55 49 6e 74 29 20 63 6f 6e 74 65 78 74  ideUInt) context
1510: 50 74 72 2d 3e 6e 75 6d 49 74 65 72 61 74 69 6f  Ptr->numIteratio
1520: 6e 73 3b 0a 20 0a 2d 20 20 20 20 2f 2a 20 53 70  ns;. .-    /* Sp
1530: 69 6e 20 77 61 69 74 20 75 6e 74 69 6c 20 67 69  in wait until gi
1540: 76 65 6e 20 74 68 65 20 72 75 6e 20 73 69 67 6e  ven the run sign
1550: 61 6c 20 2a 2f 0a 2d 20 20 20 20 77 68 69 6c 65  al */.-    while
1560: 20 28 6d 75 74 65 78 54 68 72 65 61 64 43 6f 75   (mutexThreadCou
1570: 6e 74 20 3c 20 63 6f 6e 74 65 78 74 50 74 72 2d  nt < contextPtr-
1580: 3e 6e 75 6d 54 68 72 65 61 64 73 29 20 7b 0a 2d  >numThreads) {.-
1590: 09 59 69 65 6c 64 54 6f 4f 74 68 65 72 54 68 72  .YieldToOtherThr
15a0: 65 61 64 73 28 29 3b 0a 2b 20 20 20 20 2f 2a 20  eads();.+    /* 
15b0: 57 61 69 74 20 66 6f 72 20 73 74 61 72 74 20 73  Wait for start s
15c0: 69 67 6e 61 6c 20 2a 2f 0a 2b 20 20 20 20 54 63  ignal */.+    Tc
15d0: 6c 5f 4d 75 74 65 78 4c 6f 63 6b 28 26 74 68 72  l_MutexLock(&thr
15e0: 65 61 64 53 74 61 72 74 4d 75 74 65 78 29 3b 0a  eadStartMutex);.
15f0: 2b 20 20 20 20 77 68 69 6c 65 20 28 21 74 68 72  +    while (!thr
1600: 65 61 64 43 6f 6e 74 65 78 74 50 74 72 2d 3e 72  eadContextPtr->r
1610: 75 6e 29 20 7b 0a 2b 09 54 63 6c 5f 43 6f 6e 64  un) {.+.Tcl_Cond
1620: 69 74 69 6f 6e 57 61 69 74 28 26 74 68 72 65 61  itionWait(&threa
1630: 64 53 74 61 72 74 43 6f 6e 64 2c 20 26 74 68 72  dStartCond, &thr
1640: 65 61 64 53 74 61 72 74 4d 75 74 65 78 2c 20 4e  eadStartMutex, N
1650: 55 4c 4c 29 3b 0a 20 20 20 20 20 7d 0a 2b 20 20  ULL);.     }.+  
1660: 20 20 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63    Tcl_MutexUnloc
1670: 6b 28 26 74 68 72 65 61 64 53 74 61 72 74 4d 75  k(&threadStartMu
1680: 74 65 78 29 3b 0a 20 0a 20 20 20 20 20 4c 6f 63  tex);. .     Loc
1690: 6b 54 65 73 74 43 6f 6e 74 65 78 74 28 63 6f 6e  kTestContext(con
16a0: 74 65 78 74 50 74 72 2d 3e 6e 75 6d 52 65 63 75  textPtr->numRecu
16b0: 72 73 69 6f 6e 73 29 3b 0a 20 20 20 20 20 77 68  rsions);.     wh
16c0: 69 6c 65 20 28 63 6f 6e 74 65 78 74 50 74 72 2d  ile (contextPtr-
16d0: 3e 75 2e 71 75 65 75 65 2e 74 6f 74 61 6c 45 6e  >u.queue.totalEn
16e0: 71 75 65 75 65 64 20 3c 20 6c 69 6d 69 74 29 20  queued < limit) 
16f0: 7b 0a 20 09 69 66 20 28 63 6f 6e 74 65 78 74 50  {. .if (contextP
1700: 74 72 2d 3e 75 2e 71 75 65 75 65 2e 61 76 61 69  tr->u.queue.avai
1710: 6c 61 62 6c 65 20 3d 3d 20 63 6f 6e 74 65 78 74  lable == context
1720: 50 74 72 2d 3e 75 2e 71 75 65 75 65 2e 63 61 70  Ptr->u.queue.cap
1730: 61 63 69 74 79 29 20 7b 0a 20 09 20 20 20 20 54  acity) {. .    T
1740: 63 6c 5f 54 69 6d 65 20 62 65 66 6f 72 65 2c 20  cl_Time before, 
1750: 61 66 74 65 72 3b 0a 40 40 20 2d 35 30 31 2c 31  after;.@@ -501,1
1760: 34 20 2b 35 32 31 2c 31 36 20 40 40 0a 20 0a 20  4 +521,16 @@. . 
1770: 20 20 20 20 2f 2a 20 4c 69 6d 69 74 20 6f 6e 20      /* Limit on 
1780: 74 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20  total number of 
1790: 6f 70 65 72 61 74 69 6f 6e 73 20 61 63 72 6f 73  operations acros
17a0: 73 20 61 6c 6c 20 74 68 72 65 61 64 73 20 2a 2f  s all threads */
17b0: 0a 20 20 20 20 20 54 63 6c 5f 57 69 64 65 55 49  .     Tcl_WideUI
17c0: 6e 74 20 6c 69 6d 69 74 3b 0a 20 20 20 20 20 6c  nt limit;.     l
17d0: 69 6d 69 74 20 3d 20 63 6f 6e 74 65 78 74 50 74  imit = contextPt
17e0: 72 2d 3e 6e 75 6d 54 68 72 65 61 64 73 20 2a 20  r->numThreads * 
17f0: 28 54 63 6c 5f 57 69 64 65 55 49 6e 74 29 20 63  (Tcl_WideUInt) c
1800: 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 49 74  ontextPtr->numIt
1810: 65 72 61 74 69 6f 6e 73 3b 0a 20 0a 2d 20 20 20  erations;. .-   
1820: 20 2f 2a 20 53 70 69 6e 20 77 61 69 74 20 75 6e   /* Spin wait un
1830: 74 69 6c 20 67 69 76 65 6e 20 74 68 65 20 72 75  til given the ru
1840: 6e 20 73 69 67 6e 61 6c 20 2a 2f 0a 2d 20 20 20  n signal */.-   
1850: 20 77 68 69 6c 65 20 28 6d 75 74 65 78 54 68 72   while (mutexThr
1860: 65 61 64 43 6f 75 6e 74 20 3c 20 63 6f 6e 74 65  eadCount < conte
1870: 78 74 50 74 72 2d 3e 6e 75 6d 54 68 72 65 61 64  xtPtr->numThread
1880: 73 29 20 7b 0a 2d 09 59 69 65 6c 64 54 6f 4f 74  s) {.-.YieldToOt
1890: 68 65 72 54 68 72 65 61 64 73 28 29 3b 0a 2b 20  herThreads();.+ 
18a0: 20 20 20 2f 2a 20 57 61 69 74 20 66 6f 72 20 73     /* Wait for s
18b0: 74 61 72 74 20 73 69 67 6e 61 6c 20 2a 2f 0a 2b  tart signal */.+
18c0: 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c 6f 63      Tcl_MutexLoc
18d0: 6b 28 26 74 68 72 65 61 64 53 74 61 72 74 4d 75  k(&threadStartMu
18e0: 74 65 78 29 3b 0a 2b 20 20 20 20 77 68 69 6c 65  tex);.+    while
18f0: 20 28 21 74 68 72 65 61 64 43 6f 6e 74 65 78 74   (!threadContext
1900: 50 74 72 2d 3e 72 75 6e 29 20 7b 0a 2b 09 54 63  Ptr->run) {.+.Tc
1910: 6c 5f 43 6f 6e 64 69 74 69 6f 6e 57 61 69 74 28  l_ConditionWait(
1920: 26 74 68 72 65 61 64 53 74 61 72 74 43 6f 6e 64  &threadStartCond
1930: 2c 20 26 74 68 72 65 61 64 53 74 61 72 74 4d 75  , &threadStartMu
1940: 74 65 78 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20  tex, NULL);.    
1950: 20 7d 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65   }.+    Tcl_Mute
1960: 78 55 6e 6c 6f 63 6b 28 26 74 68 72 65 61 64 53  xUnlock(&threadS
1970: 74 61 72 74 4d 75 74 65 78 29 3b 0a 20 0a 20 20  tartMutex);. .  
1980: 20 20 20 4c 6f 63 6b 54 65 73 74 43 6f 6e 74 65     LockTestConte
1990: 78 74 28 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e  xt(contextPtr->n
19a0: 75 6d 52 65 63 75 72 73 69 6f 6e 73 29 3b 0a 20  umRecursions);. 
19b0: 20 20 20 20 77 68 69 6c 65 20 28 63 6f 6e 74 65      while (conte
19c0: 78 74 50 74 72 2d 3e 75 2e 71 75 65 75 65 2e 74  xtPtr->u.queue.t
19d0: 6f 74 61 6c 44 65 71 75 65 75 65 64 20 3c 20 6c  otalDequeued < l
19e0: 69 6d 69 74 29 20 7b 0a 20 09 69 66 20 28 63 6f  imit) {. .if (co
19f0: 6e 74 65 78 74 50 74 72 2d 3e 75 2e 71 75 65 75  ntextPtr->u.queu
1a00: 65 2e 61 76 61 69 6c 61 62 6c 65 20 3d 3d 20 30  e.available == 0
1a10: 29 20 7b 0a 20 09 20 20 20 20 54 63 6c 5f 54 69  ) {. .    Tcl_Ti
1a20: 6d 65 20 62 65 66 6f 72 65 2c 20 61 66 74 65 72  me before, after
1a30: 3b 0a 0a                                         ;..