Index: trunk/psLib/src/sys/psThread.c
===================================================================
--- trunk/psLib/src/sys/psThread.c	(revision 21348)
+++ trunk/psLib/src/sys/psThread.c	(revision 28138)
@@ -121,5 +121,7 @@
     }
 
+    psThreadLock();
     psThreadJob *job = psListGetAndRemove(pending, PS_LIST_HEAD);
+    psThreadUnlock();
     return job;
 }
@@ -132,5 +134,7 @@
     }
 
+    psThreadLock();
     psThreadJob *job = psListGetAndRemove(done, PS_LIST_HEAD);
+    psThreadUnlock();
     return job;
 }
@@ -193,16 +197,11 @@
         // request a new job, if there are none available, sleep a bit
         // we have to lock here so the job queue cannot be empty yet no threads busy
-        psThreadLock();
         psThreadJob *job = NULL;        // Job to process
         while ((job = psThreadJobGetPending()) == NULL) {
-            psThreadUnlock();
             usleep(THREAD_WAIT);
-            psThreadLock(); // XXX ???
         }
         self->busy = true;
 
         psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job
-        psThreadUnlock();
-
         psAssert(task, "Couldn't find thread task %s", job->type);
         psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s (%ld supplied, expected %d)", task->type, job->args->n, task->nArgs);
@@ -216,4 +215,5 @@
         psListAdd(done, PS_LIST_TAIL, job);
         psFree(job);
+        psThreadUnlock();
 
         if (!status) {
@@ -221,5 +221,4 @@
         }
         self->busy = false;
-        psThreadUnlock();
     }
 }
@@ -257,10 +256,8 @@
 static void psThreadJobHarvest(void)
 {
-    psThreadLock();
     psThreadJob *job;           // Job from done queue
     while ((job = psThreadJobGetDone())) {
         psFree(job);
     }
-    psThreadUnlock();
     return;
 }
@@ -287,11 +284,11 @@
         }
 
-        // Harvest jobs, if requested
+        // Harvest jobs in the background, if requested
         if (harvest) {
             psThreadJobHarvest();
         }
 
+#if 0 // Thread state doesn't matter, only the pending job queue
         // are all threads idle?
-        psThreadLock();
         for (int i = 0; i < pool->n; i++) {
             psThread *thread = pool->data[i];
@@ -301,8 +298,12 @@
             }
         }
-
-        if (!pending || !pending->head) {
+#endif
+
+        psThreadLock();
+        bool more = (pending && pending->head) ? true : false; // More to process?
+        psThreadUnlock();
+
+        if (!more) {
             // Nothing in the queue
-            psThreadUnlock();
             // Ensure everything is harvested, if requested
             if (harvest) {
@@ -312,6 +313,4 @@
         }
 
-    SLEEP:
-        psThreadUnlock();
         usleep(THREAD_WAIT);
     }
