[Swift-commit] r4626 - trunk/src/org/griphyn/vdl/karajan

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Thu Jun 16 17:56:36 CDT 2011


Author: hategan
Date: 2011-06-16 17:56:36 -0500 (Thu, 16 Jun 2011)
New Revision: 4626

Modified:
   trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
   trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java
Log:
fixed potential deadlock

Modified: trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java	2011-06-16 21:30:08 UTC (rev 4625)
+++ trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java	2011-06-16 22:56:36 UTC (rev 4626)
@@ -5,11 +5,9 @@
 
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
-import org.globus.cog.karajan.stack.VariableNotFoundException;
 import org.globus.cog.karajan.stack.VariableStack;
 import org.globus.cog.karajan.workflow.events.EventTargetPair;
 import org.globus.cog.karajan.workflow.futures.FutureEvaluationException;
@@ -71,12 +69,14 @@
         return new FuturePairIterator(this, stack);
     }
 
-    public synchronized void close() {
-        closed = true;
-        Set<Object> allkeys = new HashSet<Object>(values.keySet());
-        allkeys.removeAll(keys);
-        // remaining keys must be added
-        keys.addAll(allkeys);
+    public void close() {
+        synchronized(this) {
+            closed = true;
+            Set<Object> allkeys = new HashSet<Object>(values.keySet());
+            allkeys.removeAll(keys);
+            // remaining keys must be added
+            keys.addAll(allkeys);
+        }
         notifyListeners();
     }
 
@@ -88,16 +88,20 @@
         return this;
     }
 
-    public synchronized void addModificationAction(FutureListener target,
+    public void addModificationAction(FutureListener target,
             VariableStack stack) {
-        if (listeners == null) {
-            listeners = new ArrayList<ListenerStackPair>();
+        synchronized(this) {
+            if (listeners == null) {
+                listeners = new ArrayList<ListenerStackPair>();
+            }
+    
+            listeners.add(new ListenerStackPair(target, stack));
+            if (!closed) {
+                return;
+            }
         }
-
-        listeners.add(new ListenerStackPair(target, stack));
-        if (closed) {
-            notifyListeners();
-        }
+        // closed
+        notifyListeners();
     }
 
     private void notifyListeners() {

Modified: trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java	2011-06-16 21:30:08 UTC (rev 4625)
+++ trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java	2011-06-16 22:56:36 UTC (rev 4626)
@@ -6,7 +6,6 @@
 import java.util.LinkedList;
 import java.util.List;
 
-import org.globus.cog.karajan.stack.VariableNotFoundException;
 import org.globus.cog.karajan.stack.VariableStack;
 import org.globus.cog.karajan.workflow.events.EventTargetPair;
 import org.globus.cog.karajan.workflow.futures.Future;
@@ -43,7 +42,7 @@
 		}
 	}
 
-	public synchronized void addModificationAction(FutureListener target, VariableStack stack) {
+	public void addModificationAction(FutureListener target, VariableStack stack) {
 		/**
 		 * TODO So, the strategy is the following: getValue() or something else
 		 * throws a future exception; then some entity catches that and calls
@@ -52,14 +51,18 @@
 		 * check if the future was closed or modified at the time of the call of
 		 * this method and call notifyListeners().
 		 */
-		if (listeners == null) {
-			listeners = new LinkedList<ListenerStackPair>();
-		}
-		listeners.add(new ListenerStackPair(target, stack));
-		WaitingThreadsMonitor.addThread(stack);
-		if (handle.isClosed()) {
-			notifyListeners();
-		}
+	    synchronized(this) {
+    		if (listeners == null) {
+    			listeners = new LinkedList<ListenerStackPair>();
+    		}
+    		listeners.add(new ListenerStackPair(target, stack));
+    		WaitingThreadsMonitor.addThread(stack);
+    		if (!handle.isClosed()) {
+    		    return;
+    		}
+	    }
+	    // handle.isClosed();
+		notifyListeners();
 	}
 
 	private void notifyListeners() {




More information about the Swift-commit mailing list