Index: trunk/psLib/src/sysUtils/psMemory.c
===================================================================
--- trunk/psLib/src/sysUtils/psMemory.c	(revision 648)
+++ trunk/psLib/src/sysUtils/psMemory.c	(revision 803)
@@ -8,6 +8,6 @@
  *  @author Robert Lupton, Princeton University
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-12 19:05:02 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-28 03:17:39 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,4 +31,5 @@
 static psMemBlock *lastMemBlockAllocated = NULL;
 pthread_mutex_t   memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t   memIdMutex = PTHREAD_MUTEX_INITIALIZER;
 
 /**
@@ -172,5 +173,10 @@
 psMemoryId psMemGetId(void)
 {
-    return memid + 1;
+    psMemoryId id;
+    pthread_mutex_lock(&memIdMutex);
+    id = memid + 1;
+    pthread_mutex_unlock(&memIdMutex);
+
+    return id;
 }
 
@@ -252,5 +258,10 @@
     }
 
+
+    // increment the memory id safely.
+    pthread_mutex_lock(&memBlockListMutex);
     *(psMemoryId*)&ptr->id = ++memid;
+    pthread_mutex_unlock(&memBlockListMutex);
+
     ptr->file = file;
     *(unsigned int*)&ptr->lineno = lineno;
@@ -260,4 +271,5 @@
     ptr->userMemorySize = size;
     *(void**)((int8_t*)(ptr+1)+size) = P_PS_MEMMAGIC;
+    ptr->previousBlock = NULL;
 
     // need exclusive access of the memory block list now...
@@ -265,5 +277,4 @@
 
     // insert the new block to the front of the memBlock linked-list
-    ptr->previousBlock = NULL;
     ptr->nextBlock = lastMemBlockAllocated;
     if (ptr->nextBlock != NULL) {
