Index: /tags/ipp-20111110/psLib/src/imageops/psImageConvolve.c
===================================================================
--- /tags/ipp-20111110/psLib/src/imageops/psImageConvolve.c	(revision 32716)
+++ /tags/ipp-20111110/psLib/src/imageops/psImageConvolve.c	(revision 32717)
@@ -859,11 +859,11 @@
 
             psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_PIXELS");
-            psArrayAdd(job->args, 1, out);
-            psArrayAdd(job->args, 1, (psImage*)image);
-            psArrayAdd(job->args, 1, (psImage*)mask);
+            psArrayAdd(job->args, 0, out);
+            psArrayAdd(job->args, 0, (psImage*)image);
+            psArrayAdd(job->args, 0, (psImage*)mask);
             PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK);
-            psArrayAdd(job->args, 1, (psVector*)x);
-            psArrayAdd(job->args, 1, (psVector*)y);
-            psArrayAdd(job->args, 1, gaussNorm);
+            psArrayAdd(job->args, 0, (psVector*)x);
+            psArrayAdd(job->args, 0, (psVector*)y);
+            psArrayAdd(job->args, 0, gaussNorm);
             PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
             PS_ARRAY_ADD_SCALAR(job->args, size, PS_TYPE_S32);
@@ -1203,10 +1203,10 @@
                   // allocate a job, construct the arguments for this job
                   psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANROWS");
-                  psArrayAdd(job->args, 1, calculation);
-                  psArrayAdd(job->args, 1, calcMask);
-                  psArrayAdd(job->args, 1, (psImage *) image); // cast away const
-                  psArrayAdd(job->args, 1, (psImage *) mask); // cast away const
+                  psArrayAdd(job->args, 0, calculation);
+                  psArrayAdd(job->args, 0, calcMask);
+                  psArrayAdd(job->args, 0, (psImage *) image); // cast away const
+                  psArrayAdd(job->args, 0, (psImage *) mask); // cast away const
                   PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
-                  psArrayAdd(job->args, 1, gaussNorm);
+                  psArrayAdd(job->args, 0, gaussNorm);
                   PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
                   PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
@@ -1250,9 +1250,9 @@
                   // allocate a job, construct the arguments for this job
                   psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANCOLS");
-                  psArrayAdd(job->args, 1, output);
-                  psArrayAdd(job->args, 1, calculation);
-                  psArrayAdd(job->args, 1, calcMask);
+                  psArrayAdd(job->args, 0, output);
+                  psArrayAdd(job->args, 0, calculation);
+                  psArrayAdd(job->args, 0, calcMask);
                   PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
-                  psArrayAdd(job->args, 1, gaussNorm);
+                  psArrayAdd(job->args, 0, gaussNorm);
                   PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
                   PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
@@ -1572,6 +1572,6 @@
 
             psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_CONVOLVE_MASK");
-            psArrayAdd(job->args, 1, conv);
-            psArrayAdd(job->args, 1, (psImage*)mask); // Casting away const to put on arguments
+            psArrayAdd(job->args, 0, conv);
+            psArrayAdd(job->args, 0, (psImage*)mask); // Casting away const to put on arguments
             PS_ARRAY_ADD_SCALAR(job->args, start, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, stop, PS_TYPE_S32);
@@ -1607,6 +1607,6 @@
 
             psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_CONVOLVE_MASK");
-            psArrayAdd(job->args, 1, out);
-            psArrayAdd(job->args, 1, conv);
+            psArrayAdd(job->args, 0, out);
+            psArrayAdd(job->args, 0, conv);
             PS_ARRAY_ADD_SCALAR(job->args, start, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, stop, PS_TYPE_S32);
Index: /tags/ipp-20111110/psLib/src/imageops/psImageCovariance.c
===================================================================
--- /tags/ipp-20111110/psLib/src/imageops/psImageCovariance.c	(revision 32716)
+++ /tags/ipp-20111110/psLib/src/imageops/psImageCovariance.c	(revision 32717)
@@ -177,7 +177,7 @@
             if (threaded) {
                 psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_COVARIANCE_CALCULATE");
-                psArrayAdd(job->args, 1, out);
-                psArrayAdd(job->args, 1, covar);
-                psArrayAdd(job->args, 1, (psKernel*)kernel); // Casting away const
+                psArrayAdd(job->args, 0, out);
+                psArrayAdd(job->args, 0, covar);
+                psArrayAdd(job->args, 0, (psKernel*)kernel); // Casting away const
                 PS_ARRAY_ADD_SCALAR(job->args, x, PS_TYPE_S32);
                 PS_ARRAY_ADD_SCALAR(job->args, y, PS_TYPE_S32);
@@ -345,6 +345,6 @@
             if (threaded) {
                 psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_COVARIANCE_BIN");
-                psArrayAdd(job->args, 1, out);
-                psArrayAdd(job->args, 1, covar);
+                psArrayAdd(job->args, 0, out);
+                psArrayAdd(job->args, 0, covar);
                 PS_ARRAY_ADD_SCALAR(job->args, bin, PS_TYPE_S32);
                 PS_ARRAY_ADD_SCALAR(job->args, binVal, PS_TYPE_F32);
Index: /tags/ipp-20111110/psLib/src/sys/psMemory.c
===================================================================
--- /tags/ipp-20111110/psLib/src/sys/psMemory.c	(revision 32716)
+++ /tags/ipp-20111110/psLib/src/sys/psMemory.c	(revision 32717)
@@ -56,5 +56,5 @@
 
 # define USE_SPINLOCK 0
-# define USE_HARDLOCK 0
+# define USE_HARDLOCK 1
 
 # if (USE_SPINLOCK) 
@@ -337,5 +337,5 @@
 /**** Unique ID for allocated blocks and associated accessor functions
  */
-static psMemId memid = 0;
+static volatile psMemId memid = 0;
 
 /* Return memory ID counter for next block to be allocated
@@ -384,5 +384,5 @@
 // pointer to the last mem block that was allocated.
 // This is the root of the entire memory list
-static psMemBlock *lastMemBlockAllocated = NULL;
+static volatile psMemBlock *lastMemBlockAllocated = NULL;
 
 // set lock on lastMemBlockAllocated
@@ -655,6 +655,7 @@
     memBlock->refCounter = 1;                   // one user so far
 
-    psMemBlock *last0 = lastMemBlockAllocated;
-    int flight0 = (lastMemBlockAllocated) ? lastMemBlockAllocated->inFlight : 10;
+    // XXX these lines are test lines that potentially access invalid memory
+    // XXX psMemBlock *last0 = lastMemBlockAllocated;
+    // XXX int flight0 = (lastMemBlockAllocated) ? lastMemBlockAllocated->inFlight : 10;
 
     // need exclusive access of the memory block list now...
@@ -663,10 +664,10 @@
     BLOCKLAST_LOCK ();
 
-    psMemBlock *last1 = lastMemBlockAllocated;
-    int flight1 = (lastMemBlockAllocated) ? lastMemBlockAllocated->inFlight : 10;
-
-    if (false) {
-	fprintf (stderr, "last 0 : %lld, last 1 : %lld, flight0: %d, flight1: %d\n", (long long int) last0, (long long int) last1, (int) flight0, (int) flight1);
-    }
+    // XXX psMemBlock *last1 = lastMemBlockAllocated;
+    // XXX int flight1 = (lastMemBlockAllocated) ? lastMemBlockAllocated->inFlight : 10;
+
+    // XXX if (false) {
+    // XXX 	fprintf (stderr, "last 0 : %lld, last 1 : %lld, flight0: %d, flight1: %d\n", (long long int) last0, (long long int) last1, (int) flight0, (int) flight1);
+    // XXX }
 
     // increment the memory id only after we've grabbed the memBlockListMutex this value is
@@ -679,5 +680,5 @@
         lastMemBlockAllocated->previousBlock = memBlock;
     }
-    memBlock->nextBlock = lastMemBlockAllocated;
+    memBlock->nextBlock = (psMemBlock *) lastMemBlockAllocated;
     lastMemBlockAllocated = memBlock;
 
@@ -909,9 +910,12 @@
     psS32 nleak = 0;
     psS32 j = 0;
-    psMemBlock *topBlock = lastMemBlockAllocated;
+    psMemBlock *topBlock = (psMemBlock *) lastMemBlockAllocated;
 
     // XXX move this elsewhere?
     if (fd != NULL) {
+# if (USE_HARDLOCK)
+# else
       fprintf (fd, "set %d locks, cleared %d locks, retry on %d locks (memID %ld)\n", setLock, clearLock, retryLock, memid);
+# endif
     }
 
@@ -1293,5 +1297,5 @@
 
     psS32 nbad = 0;               // number of bad blocks
-    for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
+    for (psMemBlock *memBlock = (psMemBlock *) lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
         if (isBadMemBlock(output, memBlock, __FILE__, __LINE__, __func__)) {
             nbad++;
@@ -1324,5 +1328,5 @@
 
     // loop through the linked list of memBlocks looking for a matching pointer
-    for (psMemBlock *memBlock = lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
+    for (psMemBlock *memBlock = (psMemBlock *) lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) {
         if (memBlock == addr) {
             // we found the memBlock
@@ -1375,5 +1379,5 @@
     size_t alloc = 0, persist = 0;
     size_t nalloc = 0, npersist = 0;
-    for (psMemBlock* ptr = lastMemBlockAllocated; ptr != NULL; ptr = ptr->nextBlock) {
+    for (psMemBlock* ptr = (psMemBlock *) lastMemBlockAllocated; ptr != NULL; ptr = ptr->nextBlock) {
         assert (ptr->refCounter > 0);
 
Index: /tags/ipp-20111110/psLib/src/sys/psThread.c
===================================================================
--- /tags/ipp-20111110/psLib/src/sys/psThread.c	(revision 32716)
+++ /tags/ipp-20111110/psLib/src/sys/psThread.c	(revision 32717)
@@ -91,5 +91,5 @@
 
     job->type = psStringCopy(type);
-    job->args = psArrayAlloc(0);
+    job->args = psArrayAllocEmpty(16);
     job->results = NULL;
     return job;
Index: /tags/ipp-20111110/psLib/src/types/psArray.c
===================================================================
--- /tags/ipp-20111110/psLib/src/types/psArray.c	(revision 32716)
+++ /tags/ipp-20111110/psLib/src/types/psArray.c	(revision 32717)
@@ -35,5 +35,5 @@
 #include "psSort.h"
 
-#define DEFAULT_ARRAY_ADD 10            // Default number to add to an array when not specified
+#define DEFAULT_ARRAY_ADD 8            // Default number to add to an array when not specified
 
 /*****************************************************************************
Index: /tags/ipp-20111110/psLib/src/types/psArray.h
===================================================================
--- /tags/ipp-20111110/psLib/src/types/psArray.h	(revision 32716)
+++ /tags/ipp-20111110/psLib/src/types/psArray.h	(revision 32717)
@@ -171,5 +171,5 @@
 #define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \
       psScalar *scalar = psScalarAlloc(VALUE, TYPE); \
-      psArrayAdd(ARRAY, 1, scalar); \
+      psArrayAdd(ARRAY, 0, scalar); \
       psFree(scalar); \
 }
