--- threadPoolCmd.c.old	Wed Jan 12 00:58:40 2005
+++ threadPoolCmd.c	Mon Jun 26 02:00:23 2006
@@ -506,10 +506,14 @@
                 return TCL_ERROR;
             }
             hPtr = Tcl_FindHashEntry(&tpoolPtr->jobsDone, (char*)jobId);
-            if (hPtr == NULL) {
-                continue; /* Bogus job id; ignore */
+            if (hPtr) {
+                rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr);
+            } else {
+                for (rPtr = tpoolPtr->workHead; rPtr; rPtr = rPtr->nextPtr) {
+                    if (rPtr->jobId == jobId) break;
+                }
+                if (!rPtr) continue; /* Bogus job id; ignore */
             }
-            rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr);
             if (rPtr->detached) {
                 continue; /* A detached job */
             }
@@ -627,10 +631,11 @@
                 Tcl_Free((char*)rPtr);
                 Tcl_ListObjAppendElement(interp, doneList, wObjv[ii]);
                 break;
-            } else if (listVar) {
-                Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
             }
         }
+        if (!rPtr && listVar) {
+            Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
+        }
     }
     Tcl_MutexUnlock(&tpoolPtr->mutex);
 
@@ -1074,17 +1079,18 @@
                 continue; /* Leave this woker alive */
             }
         }
+        if (!rPtr->detached) {
+            int new;
+            Tcl_SetHashValue(Tcl_CreateHashEntry(&tpoolPtr->jobsDone, 
+                                                 (char*)rPtr->jobId, &new), 
+                             (ClientData)rPtr);
+        }
         Tcl_MutexUnlock(&tpoolPtr->mutex);
         TpoolEval(interp, rPtr->script, rPtr->scriptLen, rPtr);
         Tcl_Free(rPtr->script);
         Tcl_MutexLock(&tpoolPtr->mutex);
         if (rPtr->detached) {
             Tcl_Free((char*)rPtr);
-        } else {
-            int new;
-            Tcl_SetHashValue(Tcl_CreateHashEntry(&tpoolPtr->jobsDone, 
-                                                 (char*)rPtr->jobId, &new), 
-                             (ClientData)rPtr);
         }
     }
 
