Tcl Source Code

Hex Artifact Content
Login

Artifact fd3489f7eb4a4859702ac7a2d7a02e82d7b2758ec226bad30eae96e26128f509:

Attachment "tclMutexTest.diff3" to ticket [893f8cc5db] added by chw 2025-10-06 18:38:40.
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 63 6f 6e 74 65     while (!conte
0cc0: 78 74 50 74 72 2d 3e 72 75 6e 29 20 7b 0a 2b 09  xtPtr->run) {.+.
0cd0: 54 63 6c 5f 43 6f 6e 64 69 74 69 6f 6e 57 61 69  Tcl_ConditionWai
0ce0: 74 28 26 74 68 72 65 61 64 53 74 61 72 74 43 6f  t(&threadStartCo
0cf0: 6e 64 2c 20 26 74 68 72 65 61 64 53 74 61 72 74  nd, &threadStart
0d00: 4d 75 74 65 78 2c 20 4e 55 4c 4c 29 3b 0a 20 20  Mutex, NULL);.  
0d10: 20 20 20 7d 0a 2b 20 20 20 20 54 63 6c 5f 4d 75     }.+    Tcl_Mu
0d20: 74 65 78 55 6e 6c 6f 63 6b 28 26 74 68 72 65 61  texUnlock(&threa
0d30: 64 53 74 61 72 74 4d 75 74 65 78 29 3b 0a 20 0a  dStartMutex);. .
0d40: 20 20 20 20 20 66 6f 72 20 28 69 6e 74 20 69 20       for (int i 
0d50: 3d 20 30 3b 20 69 20 3c 20 63 6f 6e 74 65 78 74  = 0; i < context
0d60: 50 74 72 2d 3e 6e 75 6d 49 74 65 72 61 74 69 6f  Ptr->numIteratio
0d70: 6e 73 3b 20 69 2b 2b 29 20 7b 0a 20 09 4c 6f 63  ns; i++) {. .Loc
0d80: 6b 54 65 73 74 43 6f 6e 74 65 78 74 28 63 6f 6e  kTestContext(con
0d90: 74 65 78 74 50 74 72 2d 3e 6e 75 6d 52 65 63 75  textPtr->numRecu
0da0: 72 73 69 6f 6e 73 29 3b 0a 20 09 54 63 6c 5f 57  rsions);. .Tcl_W
0db0: 69 64 65 55 49 6e 74 20 74 65 6d 70 20 3d 20 63  ideUInt temp = c
0dc0: 6f 6e 74 65 78 74 50 74 72 2d 3e 75 2e 63 6f 75  ontextPtr->u.cou
0dd0: 6e 74 65 72 3b 0a 20 09 69 66 20 28 63 6f 6e 74  nter;. .if (cont
0de0: 65 78 74 50 74 72 2d 3e 79 69 65 6c 64 29 20 7b  extPtr->yield) {
0df0: 0a 40 40 20 2d 33 32 37 2c 31 30 20 2b 33 33 38  .@@ -327,10 +338
0e00: 2c 31 31 20 40 40 0a 20 09 72 65 74 75 72 6e 20  ,11 @@. .return 
0e10: 54 43 4c 5f 45 52 52 4f 52 3b 0a 20 20 20 20 20  TCL_ERROR;.     
0e20: 7d 0a 20 20 20 20 20 69 6e 74 20 6e 75 6d 50 72  }.     int numPr
0e30: 6f 64 75 63 65 72 73 20 3d 20 63 6f 6e 74 65 78  oducers = contex
0e40: 74 50 74 72 2d 3e 6e 75 6d 54 68 72 65 61 64 73  tPtr->numThreads
0e50: 20 2f 20 32 3b 0a 20 20 20 20 20 69 6e 74 20 6e   / 2;.     int n
0e60: 75 6d 43 6f 6e 73 75 6d 65 72 73 20 3d 20 63 6f  umConsumers = co
0e70: 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 54 68 72  ntextPtr->numThr
0e80: 65 61 64 73 20 2d 20 6e 75 6d 50 72 6f 64 75 63  eads - numProduc
0e90: 65 72 73 3b 0a 20 0a 2b 20 20 20 20 63 6f 6e 74  ers;. .+    cont
0ea0: 65 78 74 50 74 72 2d 3e 72 75 6e 20 3d 20 30 3b  extPtr->run = 0;
0eb0: 0a 20 20 20 20 20 63 6f 6e 74 65 78 74 50 74 72  .     contextPtr
0ec0: 2d 3e 75 2e 71 75 65 75 65 2e 63 61 6e 44 65 71  ->u.queue.canDeq
0ed0: 75 65 75 65 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20  ueue = NULL;.   
0ee0: 20 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 75 2e    contextPtr->u.
0ef0: 71 75 65 75 65 2e 63 61 6e 45 6e 71 75 65 75 65  queue.canEnqueue
0f00: 20 3d 20 4e 55 4c 4c 3b 0a 20 0a 20 20 20 20 20   = NULL;. .     
0f10: 2f 2a 0a 20 20 20 20 20 20 2a 20 61 76 61 69 6c  /*.      * avail
0f20: 61 62 6c 65 20 74 72 61 63 6b 73 20 68 6f 77 20  able tracks how 
0f30: 6d 61 6e 79 20 65 6c 65 6d 65 6e 74 73 20 69 6e  many elements in
0f40: 20 74 68 65 20 76 69 72 74 75 61 6c 20 71 75 65   the virtual que
0f50: 75 65 0a 40 40 20 2d 33 34 34 2c 31 31 20 2b 33  ue.@@ -344,11 +3
0f60: 35 36 2c 31 34 20 40 40 0a 20 20 20 20 20 4d 75  56,14 @@.     Mu
0f70: 74 65 78 54 68 72 65 61 64 43 6f 6e 74 65 78 74  texThreadContext
0f80: 20 2a 63 6f 6e 73 75 6d 65 72 43 6f 6e 74 65 78   *consumerContex
0f90: 74 73 50 74 72 20 3d 20 28 4d 75 74 65 78 54 68  tsPtr = (MutexTh
0fa0: 72 65 61 64 43 6f 6e 74 65 78 74 20 2a 29 54 63  readContext *)Tc
0fb0: 6c 5f 41 6c 6c 6f 63 28 0a 20 09 20 20 20 20 73  l_Alloc(. .    s
0fc0: 69 7a 65 6f 66 28 2a 63 6f 6e 73 75 6d 65 72 43  izeof(*consumerC
0fd0: 6f 6e 74 65 78 74 73 50 74 72 29 20 2a 20 6e 75  ontextsPtr) * nu
0fe0: 6d 43 6f 6e 73 75 6d 65 72 73 29 3b 0a 20 20 20  mConsumers);.   
0ff0: 20 20 4d 75 74 65 78 54 68 72 65 61 64 43 6f 6e    MutexThreadCon
1000: 74 65 78 74 20 2a 70 72 6f 64 75 63 65 72 43 6f  text *producerCo
1010: 6e 74 65 78 74 73 50 74 72 20 3d 20 28 4d 75 74  ntextsPtr = (Mut
1020: 65 78 54 68 72 65 61 64 43 6f 6e 74 65 78 74 20  exThreadContext 
1030: 2a 29 54 63 6c 5f 41 6c 6c 6f 63 28 0a 20 09 20  *)Tcl_Alloc(. . 
1040: 20 20 20 73 69 7a 65 6f 66 28 2a 70 72 6f 64 75     sizeof(*produ
1050: 63 65 72 43 6f 6e 74 65 78 74 73 50 74 72 29 20  cerContextsPtr) 
1060: 2a 20 6e 75 6d 50 72 6f 64 75 63 65 72 73 29 3b  * numProducers);
1070: 0a 20 0a 2d 20 20 20 20 6d 75 74 65 78 54 68 72  . .-    mutexThr
1080: 65 61 64 43 6f 75 6e 74 20 3d 20 30 3b 0a 2b 20  eadCount = 0;.+ 
1090: 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c 6f 63 6b     Tcl_MutexLock
10a0: 28 26 74 68 72 65 61 64 53 74 61 72 74 4d 75 74  (&threadStartMut
10b0: 65 78 29 3b 0a 2b 20 20 20 20 2f 2a 20 49 6e 66  ex);.+    /* Inf
10c0: 6c 61 74 65 20 74 68 72 65 61 64 53 74 61 72 74  late threadStart
10d0: 43 6f 6e 64 20 66 6f 72 20 6c 61 74 65 72 20 2a  Cond for later *
10e0: 2f 0a 2b 20 20 20 20 54 63 6c 5f 54 69 6d 65 20  /.+    Tcl_Time 
10f0: 6e 75 6c 6c 54 69 6d 65 20 3d 20 7b 20 30 2c 20  nullTime = { 0, 
1100: 30 20 7d 3b 0a 2b 20 20 20 20 54 63 6c 5f 43 6f  0 };.+    Tcl_Co
1110: 6e 64 69 74 69 6f 6e 57 61 69 74 28 26 74 68 72  nditionWait(&thr
1120: 65 61 64 53 74 61 72 74 43 6f 6e 64 2c 20 26 74  eadStartCond, &t
1130: 68 72 65 61 64 53 74 61 72 74 4d 75 74 65 78 2c  hreadStartMutex,
1140: 20 26 6e 75 6c 6c 54 69 6d 65 29 3b 0a 20 0a 20   &nullTime);. . 
1150: 20 20 20 20 66 6f 72 20 28 69 6e 74 20 69 20 3d      for (int i =
1160: 20 30 3b 20 69 20 3c 20 6e 75 6d 43 6f 6e 73 75   0; i < numConsu
1170: 6d 65 72 73 3b 20 69 2b 2b 29 20 7b 0a 20 09 63  mers; i++) {. .c
1180: 6f 6e 73 75 6d 65 72 43 6f 6e 74 65 78 74 73 50  onsumerContextsP
1190: 74 72 5b 69 5d 2e 73 68 61 72 65 64 43 6f 6e 74  tr[i].sharedCont
11a0: 65 78 74 50 74 72 20 3d 20 63 6f 6e 74 65 78 74  extPtr = context
11b0: 50 74 72 3b 0a 20 09 63 6f 6e 73 75 6d 65 72 43  Ptr;. .consumerC
11c0: 6f 6e 74 65 78 74 73 50 74 72 5b 69 5d 2e 6e 75  ontextsPtr[i].nu
11d0: 6d 4f 70 65 72 61 74 69 6f 6e 73 20 3d 20 30 3b  mOperations = 0;
11e0: 0a 20 09 63 6f 6e 73 75 6d 65 72 43 6f 6e 74 65  . .consumerConte
11f0: 78 74 73 50 74 72 5b 69 5d 2e 74 69 6d 65 6f 75  xtsPtr[i].timeou
1200: 74 73 20 3d 20 30 3b 0a 40 40 20 2d 33 37 30 2c  ts = 0;.@@ -370,
1210: 31 31 20 2b 33 38 35 2c 31 34 20 40 40 0a 20 09  11 +385,14 @@. .
1220: 09 54 43 4c 5f 54 48 52 45 41 44 5f 53 54 41 43  .TCL_THREAD_STAC
1230: 4b 5f 44 45 46 41 55 4c 54 2c 20 54 43 4c 5f 54  K_DEFAULT, TCL_T
1240: 48 52 45 41 44 5f 4a 4f 49 4e 41 42 4c 45 29 20  HREAD_JOINABLE) 
1250: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 20 09 20  != TCL_OK) {. . 
1260: 20 20 20 54 63 6c 5f 50 61 6e 69 63 28 22 46 61     Tcl_Panic("Fa
1270: 69 6c 65 64 20 74 6f 20 63 72 65 61 74 65 20 25  iled to create %
1280: 64 27 74 68 20 74 68 72 65 61 64 5c 6e 22 2c 20  d'th thread\n", 
1290: 28 69 6e 74 29 20 69 29 3b 0a 20 09 7d 0a 20 20  (int) i);. .}.  
12a0: 20 20 20 7d 0a 20 0a 2d 20 20 20 20 6d 75 74 65     }. .-    mute
12b0: 78 54 68 72 65 61 64 43 6f 75 6e 74 20 3d 20 63  xThreadCount = c
12c0: 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 54 68  ontextPtr->numTh
12d0: 72 65 61 64 73 3b 20 2f 2a 20 57 69 6c 6c 20 74  reads; /* Will t
12e0: 72 69 67 67 65 72 20 61 6c 6c 20 74 68 72 65 61  rigger all threa
12f0: 64 73 20 2a 2f 0a 2b 20 20 20 20 2f 2a 20 54 72  ds */.+    /* Tr
1300: 69 67 67 65 72 20 73 74 61 72 74 20 73 69 67 6e  igger start sign
1310: 61 6c 20 2a 2f 0a 2b 20 20 20 20 63 6f 6e 74 65  al */.+    conte
1320: 78 74 50 74 72 2d 3e 72 75 6e 20 3d 20 31 3b 0a  xtPtr->run = 1;.
1330: 2b 20 20 20 20 54 63 6c 5f 43 6f 6e 64 69 74 69  +    Tcl_Conditi
1340: 6f 6e 4e 6f 74 69 66 79 28 26 74 68 72 65 61 64  onNotify(&thread
1350: 53 74 61 72 74 43 6f 6e 64 29 3b 0a 2b 20 20 20  StartCond);.+   
1360: 20 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b   Tcl_MutexUnlock
1370: 28 26 74 68 72 65 61 64 53 74 61 72 74 4d 75 74  (&threadStartMut
1380: 65 78 29 3b 0a 20 0a 20 20 20 20 20 2f 2a 20 50  ex);. .     /* P
1390: 72 6f 64 75 63 65 72 20 74 6f 74 61 6c 2c 20 74  roducer total, t
13a0: 68 72 65 61 64 2c 20 74 69 6d 65 6f 75 74 73 2c  hread, timeouts,
13b0: 20 43 6f 6e 73 75 6d 65 72 20 74 6f 74 61 6c 2c   Consumer total,
13c0: 20 74 68 72 65 61 64 2c 20 74 69 6d 65 6f 75 74   thread, timeout
13d0: 73 20 2a 2f 0a 20 20 20 20 20 54 63 6c 5f 4f 62  s */.     Tcl_Ob
13e0: 6a 20 2a 72 65 73 75 6c 74 73 5b 36 5d 3b 0a 20  j *results[6];. 
13f0: 20 20 20 20 72 65 73 75 6c 74 73 5b 31 5d 20 3d      results[1] =
1400: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28   Tcl_NewListObj(
1410: 6e 75 6d 50 72 6f 64 75 63 65 72 73 2c 20 4e 55  numProducers, NU
1420: 4c 4c 29 3b 0a 20 20 20 20 20 72 65 73 75 6c 74  LL);.     result
1430: 73 5b 34 5d 20 3d 20 54 63 6c 5f 4e 65 77 4c 69  s[4] = Tcl_NewLi
1440: 73 74 4f 62 6a 28 6e 75 6d 43 6f 6e 73 75 6d 65  stObj(numConsume
1450: 72 73 2c 20 4e 55 4c 4c 29 3b 0a 40 40 20 2d 34  rs, NULL);.@@ -4
1460: 33 39 2c 31 34 20 2b 34 35 37 2c 31 36 20 40 40  39,14 +457,16 @@
1470: 0a 20 0a 20 20 20 20 20 2f 2a 20 4c 69 6d 69 74  . .     /* Limit
1480: 20 6f 6e 20 74 6f 74 61 6c 20 6e 75 6d 62 65 72   on total number
1490: 20 6f 66 20 6f 70 65 72 61 74 69 6f 6e 73 20 61   of operations a
14a0: 63 72 6f 73 73 20 61 6c 6c 20 74 68 72 65 61 64  cross all thread
14b0: 73 20 2a 2f 0a 20 20 20 20 20 54 63 6c 5f 57 69  s */.     Tcl_Wi
14c0: 64 65 55 49 6e 74 20 6c 69 6d 69 74 3b 0a 20 20  deUInt limit;.  
14d0: 20 20 20 6c 69 6d 69 74 20 3d 20 63 6f 6e 74 65     limit = conte
14e0: 78 74 50 74 72 2d 3e 6e 75 6d 54 68 72 65 61 64  xtPtr->numThread
14f0: 73 20 2a 20 28 54 63 6c 5f 57 69 64 65 55 49 6e  s * (Tcl_WideUIn
1500: 74 29 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e  t) contextPtr->n
1510: 75 6d 49 74 65 72 61 74 69 6f 6e 73 3b 0a 20 0a  umIterations;. .
1520: 2d 20 20 20 20 2f 2a 20 53 70 69 6e 20 77 61 69  -    /* Spin wai
1530: 74 20 75 6e 74 69 6c 20 67 69 76 65 6e 20 74 68  t until given th
1540: 65 20 72 75 6e 20 73 69 67 6e 61 6c 20 2a 2f 0a  e run signal */.
1550: 2d 20 20 20 20 77 68 69 6c 65 20 28 6d 75 74 65  -    while (mute
1560: 78 54 68 72 65 61 64 43 6f 75 6e 74 20 3c 20 63  xThreadCount < c
1570: 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 54 68  ontextPtr->numTh
1580: 72 65 61 64 73 29 20 7b 0a 2d 09 59 69 65 6c 64  reads) {.-.Yield
1590: 54 6f 4f 74 68 65 72 54 68 72 65 61 64 73 28 29  ToOtherThreads()
15a0: 3b 0a 2b 20 20 20 20 2f 2a 20 57 61 69 74 20 66  ;.+    /* Wait f
15b0: 6f 72 20 73 74 61 72 74 20 73 69 67 6e 61 6c 20  or start signal 
15c0: 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65  */.+    Tcl_Mute
15d0: 78 4c 6f 63 6b 28 26 74 68 72 65 61 64 53 74 61  xLock(&threadSta
15e0: 72 74 4d 75 74 65 78 29 3b 0a 2b 20 20 20 20 77  rtMutex);.+    w
15f0: 68 69 6c 65 20 28 21 63 6f 6e 74 65 78 74 50 74  hile (!contextPt
1600: 72 2d 3e 72 75 6e 29 20 7b 0a 2b 09 54 63 6c 5f  r->run) {.+.Tcl_
1610: 43 6f 6e 64 69 74 69 6f 6e 57 61 69 74 28 26 74  ConditionWait(&t
1620: 68 72 65 61 64 53 74 61 72 74 43 6f 6e 64 2c 20  hreadStartCond, 
1630: 26 74 68 72 65 61 64 53 74 61 72 74 4d 75 74 65  &threadStartMute
1640: 78 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20 7d  x, NULL);.     }
1650: 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 55  .+    Tcl_MutexU
1660: 6e 6c 6f 63 6b 28 26 74 68 72 65 61 64 53 74 61  nlock(&threadSta
1670: 72 74 4d 75 74 65 78 29 3b 0a 20 0a 20 20 20 20  rtMutex);. .    
1680: 20 4c 6f 63 6b 54 65 73 74 43 6f 6e 74 65 78 74   LockTestContext
1690: 28 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d  (contextPtr->num
16a0: 52 65 63 75 72 73 69 6f 6e 73 29 3b 0a 20 20 20  Recursions);.   
16b0: 20 20 77 68 69 6c 65 20 28 63 6f 6e 74 65 78 74    while (context
16c0: 50 74 72 2d 3e 75 2e 71 75 65 75 65 2e 74 6f 74  Ptr->u.queue.tot
16d0: 61 6c 45 6e 71 75 65 75 65 64 20 3c 20 6c 69 6d  alEnqueued < lim
16e0: 69 74 29 20 7b 0a 20 09 69 66 20 28 63 6f 6e 74  it) {. .if (cont
16f0: 65 78 74 50 74 72 2d 3e 75 2e 71 75 65 75 65 2e  extPtr->u.queue.
1700: 61 76 61 69 6c 61 62 6c 65 20 3d 3d 20 63 6f 6e  available == con
1710: 74 65 78 74 50 74 72 2d 3e 75 2e 71 75 65 75 65  textPtr->u.queue
1720: 2e 63 61 70 61 63 69 74 79 29 20 7b 0a 20 09 20  .capacity) {. . 
1730: 20 20 20 54 63 6c 5f 54 69 6d 65 20 62 65 66 6f     Tcl_Time befo
1740: 72 65 2c 20 61 66 74 65 72 3b 0a 40 40 20 2d 35  re, after;.@@ -5
1750: 30 31 2c 31 34 20 2b 35 32 31 2c 31 36 20 40 40  01,14 +521,16 @@
1760: 0a 20 0a 20 20 20 20 20 2f 2a 20 4c 69 6d 69 74  . .     /* Limit
1770: 20 6f 6e 20 74 6f 74 61 6c 20 6e 75 6d 62 65 72   on total number
1780: 20 6f 66 20 6f 70 65 72 61 74 69 6f 6e 73 20 61   of operations a
1790: 63 72 6f 73 73 20 61 6c 6c 20 74 68 72 65 61 64  cross all thread
17a0: 73 20 2a 2f 0a 20 20 20 20 20 54 63 6c 5f 57 69  s */.     Tcl_Wi
17b0: 64 65 55 49 6e 74 20 6c 69 6d 69 74 3b 0a 20 20  deUInt limit;.  
17c0: 20 20 20 6c 69 6d 69 74 20 3d 20 63 6f 6e 74 65     limit = conte
17d0: 78 74 50 74 72 2d 3e 6e 75 6d 54 68 72 65 61 64  xtPtr->numThread
17e0: 73 20 2a 20 28 54 63 6c 5f 57 69 64 65 55 49 6e  s * (Tcl_WideUIn
17f0: 74 29 20 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e  t) contextPtr->n
1800: 75 6d 49 74 65 72 61 74 69 6f 6e 73 3b 0a 20 0a  umIterations;. .
1810: 2d 20 20 20 20 2f 2a 20 53 70 69 6e 20 77 61 69  -    /* Spin wai
1820: 74 20 75 6e 74 69 6c 20 67 69 76 65 6e 20 74 68  t until given th
1830: 65 20 72 75 6e 20 73 69 67 6e 61 6c 20 2a 2f 0a  e run signal */.
1840: 2d 20 20 20 20 77 68 69 6c 65 20 28 6d 75 74 65  -    while (mute
1850: 78 54 68 72 65 61 64 43 6f 75 6e 74 20 3c 20 63  xThreadCount < c
1860: 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d 54 68  ontextPtr->numTh
1870: 72 65 61 64 73 29 20 7b 0a 2d 09 59 69 65 6c 64  reads) {.-.Yield
1880: 54 6f 4f 74 68 65 72 54 68 72 65 61 64 73 28 29  ToOtherThreads()
1890: 3b 0a 2b 20 20 20 20 2f 2a 20 57 61 69 74 20 66  ;.+    /* Wait f
18a0: 6f 72 20 73 74 61 72 74 20 73 69 67 6e 61 6c 20  or start signal 
18b0: 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65  */.+    Tcl_Mute
18c0: 78 4c 6f 63 6b 28 26 74 68 72 65 61 64 53 74 61  xLock(&threadSta
18d0: 72 74 4d 75 74 65 78 29 3b 0a 2b 20 20 20 20 77  rtMutex);.+    w
18e0: 68 69 6c 65 20 28 21 63 6f 6e 74 65 78 74 50 74  hile (!contextPt
18f0: 72 2d 3e 72 75 6e 29 20 7b 0a 2b 09 54 63 6c 5f  r->run) {.+.Tcl_
1900: 43 6f 6e 64 69 74 69 6f 6e 57 61 69 74 28 26 74  ConditionWait(&t
1910: 68 72 65 61 64 53 74 61 72 74 43 6f 6e 64 2c 20  hreadStartCond, 
1920: 26 74 68 72 65 61 64 53 74 61 72 74 4d 75 74 65  &threadStartMute
1930: 78 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20 7d  x, NULL);.     }
1940: 0a 2b 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 55  .+    Tcl_MutexU
1950: 6e 6c 6f 63 6b 28 26 74 68 72 65 61 64 53 74 61  nlock(&threadSta
1960: 72 74 4d 75 74 65 78 29 3b 0a 20 0a 20 20 20 20  rtMutex);. .    
1970: 20 4c 6f 63 6b 54 65 73 74 43 6f 6e 74 65 78 74   LockTestContext
1980: 28 63 6f 6e 74 65 78 74 50 74 72 2d 3e 6e 75 6d  (contextPtr->num
1990: 52 65 63 75 72 73 69 6f 6e 73 29 3b 0a 20 20 20  Recursions);.   
19a0: 20 20 77 68 69 6c 65 20 28 63 6f 6e 74 65 78 74    while (context
19b0: 50 74 72 2d 3e 75 2e 71 75 65 75 65 2e 74 6f 74  Ptr->u.queue.tot
19c0: 61 6c 44 65 71 75 65 75 65 64 20 3c 20 6c 69 6d  alDequeued < lim
19d0: 69 74 29 20 7b 0a 20 09 69 66 20 28 63 6f 6e 74  it) {. .if (cont
19e0: 65 78 74 50 74 72 2d 3e 75 2e 71 75 65 75 65 2e  extPtr->u.queue.
19f0: 61 76 61 69 6c 61 62 6c 65 20 3d 3d 20 30 29 20  available == 0) 
1a00: 7b 0a 20 09 20 20 20 20 54 63 6c 5f 54 69 6d 65  {. .    Tcl_Time
1a10: 20 62 65 66 6f 72 65 2c 20 61 66 74 65 72 3b 0a   before, after;.
1a20: 0a                                               .