Index: trunk/psLib/src/sys/psThread.c
===================================================================
--- trunk/psLib/src/sys/psThread.c	(revision 18953)
+++ trunk/psLib/src/sys/psThread.c	(revision 19016)
@@ -14,8 +14,10 @@
 #include "psList.h"
 #include "psArray.h"
+#include "psHash.h"
 #include "psString.h"
 #include "psThread.h"
 
 #define THREAD_WAIT 10000               // Microseconds to wait for threads
+#define TASK_BUCKETS 8                  // Number of hash buckets for task list
 
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // Mutex for locking threads
@@ -23,5 +25,6 @@
 static psList *done = NULL;             // queue of done jobs
 static psArray *pool = NULL;            // array of defined threads
-static psArray *tasks = NULL;           // queue of tasks
+static psHash *tasks = NULL;            // List of defined tasks
+
 
 /***** basic thread functions *****/
@@ -92,16 +95,8 @@
 
         // find the corresponding task and run it
-        for (int i = 0; i < tasks->n; i++) {
-            psThreadTask *task = tasks->data[i];
-            if (strcmp (job->type, task->type) != 0) {
-                continue;
-            }
-            psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s", task->type);
-
-            bool status = task->function(job);
-            return status;
-        }
-        // Programming error
-        psAbort("Unable to find job %s", job->type);
+        psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job
+        psAssert(task, "Unable to find task %s", job->type);
+        psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s", task->type);
+        return task->function(job);
     }
 
@@ -164,9 +159,15 @@
 
     if (!tasks) {
-        tasks = psArrayAllocEmpty(8);
-    }
-
-    psArrayAdd(tasks, 1, task);
-    return true;
+        tasks = psHashAlloc(TASK_BUCKETS);
+    }
+
+    return psHashAdd(tasks, task->type, task);
+}
+
+bool psThreadTaskDelete(const char *type)
+{
+    PS_ASSERT_STRING_NON_EMPTY(type, false);
+
+    return psHashRemove(tasks, type);
 }
 
@@ -198,36 +199,24 @@
         self->busy = true;
 
-        bool found = false;             // Found the job?
-        for (int i = 0; i < tasks->n; i++) {
-            psThreadTask *task = tasks->data[i]; // Task to do
-            if (strcmp(job->type, task->type) != 0) {
-                continue;
-            }
-            found = true;
-
-            psThreadUnlock();
-            psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s", task->type);
-
-            bool status = task->function(job); // Status of executing task
-
-            // Put the completed job on the 'done' queue
-            psThreadLock();
-            if (!done) {
-                done = psListAlloc(NULL);
-            }
-            psListAdd(done, PS_LIST_TAIL, job);
-            psFree(job);
-
-            if (!status) {
-                self->fault = true;
-            }
-            self->busy = false;
-            break;
-        }
+        psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job
         psThreadUnlock();
-        if (!found) {
-            // Programming error
-            psAbort("Unable to find job %s", job->type);
-        }
+
+        psAssert(task, "Couldn't find thread task %s", job->type);
+        psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s", task->type);
+        bool status = task->function(job); // Status of executing task
+
+        // Put the completed job on the 'done' queue
+        psThreadLock();
+        if (!done) {
+            done = psListAlloc(NULL);
+        }
+        psListAdd(done, PS_LIST_TAIL, job);
+        psFree(job);
+
+        if (!status) {
+            self->fault = true;
+        }
+        self->busy = false;
+        psThreadUnlock();
     }
 }
