Tcl package Thread source code

Artifact [fe3db7eb4b]
Login

Artifact fe3db7eb4bed8f83b5ac60943a52884b6aad2cb8:

Attachment "tpoolcmd.diff" to ticket [d9c95d3ed3] added by bovine 2016-11-12 03:54:00.
diff --git a/generic/threadPoolCmd.c b/generic/threadPoolCmd.c
index 4fc3d86..58d088a 100644
--- a/generic/threadPoolCmd.c
+++ b/generic/threadPoolCmd.c
@@ -386,28 +386,23 @@ TpoolPostObjCmd(dummy, interp, objc, objv)
 
     Tcl_MutexLock(&tpoolPtr->mutex);
     if (nowait) {
-        if (tpoolPtr->numWorkers == 0) {
+        /*
+         * If there are no idle worker threads, start some new
+         * unless we are already running max number of workers.
+         * In that case don't wait and just queue the job.
+         */
+
+        if (tpoolPtr->idleWorkers == 0 &&
+            tpoolPtr->numWorkers < tpoolPtr->maxWorkers) {
 
             /*
-             * Assure there is at least one worker running.
+             * No more free workers; start new one
              */
 
-            PushWaiter(tpoolPtr);
             if (CreateWorker(interp, tpoolPtr) != TCL_OK) {
                 Tcl_MutexUnlock(&tpoolPtr->mutex);
                 return TCL_ERROR;
             }
-
-            /*
-             * Wait for worker to start while servicing the event loop
-             */
-
-            Tcl_MutexUnlock(&tpoolPtr->mutex);
-            tsdPtr->stop = -1;
-            while(tsdPtr->stop == -1) {
-                Tcl_DoOneEvent(TCL_ALL_EVENTS);
-            }
-            Tcl_MutexLock(&tpoolPtr->mutex);
         }
     } else {