Index: /branches/eam_branches/ppStack.20211015/src/ppStackThread.c
===================================================================
--- /branches/eam_branches/ppStack.20211015/src/ppStackThread.c	(revision 41845)
+++ /branches/eam_branches/ppStack.20211015/src/ppStackThread.c	(revision 41846)
@@ -19,4 +19,6 @@
     thread->firstScan = 0;
     thread->lastScan = 0;
+    thread->entry = -1; // this gets assigned after allocation
+    thread->status = PPSTACK_THREAD_NEW;
     return thread;
 }
@@ -124,5 +126,7 @@
             readouts->data[j] = ro;
         }
-        threads->data[i] = ppStackThreadAlloc(readouts);
+        ppStackThread *thread = ppStackThreadAlloc(readouts);
+	thread->entry = i;
+        threads->data[i] = thread;
         psFree(readouts);               // Drop reference
     }
@@ -157,6 +161,8 @@
     while (true) {
         // check for any groups which can read data
+	// NOTE: threads->n is set (in ppStackThreadDataSetup) to be 1 more than the argument to -threads
         for (int j = 0; j < threads->n; j++) {
             ppStackThread *thread = threads->data[j];
+	    // fprintf (stderr, "grab thread %d, scan: %d - %d : busy: %d read: %d status: %d\n", thread->entry, thread->firstScan, thread->lastScan, thread->busy, thread->read, thread->status);
             if (thread->read) {
                 continue;
@@ -166,4 +172,5 @@
             thread->lastScan = stack->lastScan + rows;
             stack->lastScan = thread->lastScan;
+	    thread->status = PPSTACK_THREAD_READ;
 
             psArray *readouts = thread->readouts;
@@ -172,4 +179,5 @@
 
             psTrace("ppStack", 2, "Reading data for chunk %d into group %d....\n", numChunk, j);
+            // fprintf (stderr, "Reading data for chunk %d into group %d (thread %d, scan: %d - %d)....\n", numChunk, j, thread->entry, thread->firstScan, thread->lastScan);
             for (int i = 0; i < readouts->n; i++) {
                 pmReadout *ro = readouts->data[i]; // Input readout
@@ -177,4 +185,6 @@
                     continue;
                 }
+
+		// fprintf (stderr, "read data for readout %d\n", i);
 
                 // override the recorded last scan
@@ -232,4 +242,5 @@
 
             thread->read = thread->busy = true;
+	    thread->status = PPSTACK_THREAD_RUN;
             return thread;
         }
@@ -239,7 +250,10 @@
         for (int j = 0; j < threads->n; j++) {
             ppStackThread *thread = threads->data[j];
+	    // fprintf (stderr, "test thread %d, scan: %d - %d : busy: %d, read: %d, status: %d\n", thread->entry, thread->firstScan, thread->lastScan, thread->busy, thread->read, thread->status);
+
             if (thread->busy) {
                 continue;
             }
+	    thread->status = PPSTACK_THREAD_NEW;
             thread->read = false;
             wait = false;
