From 16eddea3cc7cfc5e038441198b924d0662ccc9e2 Mon Sep 17 00:00:00 2001
From: Walt Mankowski <wmankowski@coe.drexel.edu>
Date: Sat, 23 Jul 2016 14:29:21 -0400
Subject: [PATCH] more debugging of broken thread code

---
 .../Demo_Pixel_Replication_Threads.java       | 22 ++++++++++++++-----
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/srcx/ImageJ/Demo_Pixel_Replication_Threads.java b/srcx/ImageJ/Demo_Pixel_Replication_Threads.java
index f3b5349..0c86c00 100755
--- a/srcx/ImageJ/Demo_Pixel_Replication_Threads.java
+++ b/srcx/ImageJ/Demo_Pixel_Replication_Threads.java
@@ -9,6 +9,7 @@ import java.nio.FloatBuffer;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Random;
+import java.time.LocalTime;
 
 import static org.bytedeco.javacpp.opencv_core.*;
 import static org.bytedeco.javacpp.opencv_imgproc.*;
@@ -65,16 +66,17 @@ public class Demo_Pixel_Replication_Threads implements PlugInFilter {
             Mat initMeans = randomInitMeans(k);
             IJ.log(String.format("thread %d em randomInitMeans();", idx));
 
-            synchronized(lock1) {
+            // synchronized(lock1) {
             // try {
-                IJ.log(String.format("before, thread %d, trained ", idx) + em.isTrained());
-                em.trainE(emMat, initMeans, new Mat(), new Mat(), logLikelihoods, labels, new Mat());
-                IJ.log(String.format("after, thread %d, trained ", idx) + em.isTrained());
+                // IJ.log(String.format("before, thread %d, trained ", idx) + em.isTrained());
+                // em.trainE(emMat, initMeans, new Mat(), new Mat(), logLikelihoods, labels, new Mat());
+                train(em, emMat, initMeans, new Mat(), new Mat(), logLikelihoods, labels, new Mat());
+                // IJ.log(String.format("after, thread %d, trained ", idx) + em.isTrained());
             // } catch (Exception e) {
             //     IJ.log("Caught exception in em.trainE: " + e.getMessage());
             // }
-            }
-            IJ.log(String.format("thread %d em em.trainE();", idx));
+            // }
+            // IJ.log(String.format("thread %d em em.trainE();", idx));
 
             synchronized(lock2) {
                 ems[idx] = em;
@@ -82,6 +84,14 @@ public class Demo_Pixel_Replication_Threads implements PlugInFilter {
             }
             IJ.log(String.format("replicate %d score = %f", idx, em_scores[idx]));
         }
+
+        public synchronized void train(EM em, Mat emMat, Mat initMeans, Mat tmp1, Mat tmp2, Mat logLikelihoods, Mat labels, Mat tmp3) {
+            IJ.log(String.format("%s before, thread %d, trained ", LocalTime.now(), idx) + em.isTrained());
+            em.trainE(emMat, initMeans, new Mat(), new Mat(), logLikelihoods, labels, new Mat());
+            IJ.log(String.format("%s after, thread %d, trained ", LocalTime.now(), idx) + em.isTrained());
+            IJ.log(String.format("%s thread %d em em.trainE();", LocalTime.now(), idx));
+        }
+
     }
 
     public Demo_Pixel_Replication_Threads() {
-- 
GitLab