[Swift-commit] r7890 - trunk/src/org/griphyn/vdl/karajan/lib
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Fri May 30 18:25:27 CDT 2014
Author: hategan
Date: 2014-05-30 18:25:27 -0500 (Fri, 30 May 2014)
New Revision: 7890
Modified:
trunk/src/org/griphyn/vdl/karajan/lib/While.java
Log:
fixed thread id issue in iterate() which can cause duplicate mapping errors
Modified: trunk/src/org/griphyn/vdl/karajan/lib/While.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/While.java 2014-05-30 04:19:02 UTC (rev 7889)
+++ trunk/src/org/griphyn/vdl/karajan/lib/While.java 2014-05-30 23:25:27 UTC (rev 7890)
@@ -12,6 +12,7 @@
import java.util.LinkedList;
import java.util.List;
+import k.rt.KRunnable;
import k.rt.SingleValueChannel;
import k.rt.Stack;
import k.thr.LWThread;
@@ -80,42 +81,55 @@
int i = thr.checkSliceAndPopState();
SingleValueChannel<Object> next = (SingleValueChannel<Object>) thr.popState();
List<RefCount> drefs = (List<RefCount>) thr.popState();
+ LWThread thr2 = (LWThread) thr.popState();
Stack stack = thr.getStack();
try {
- switch(i) {
- case 0:
- drefs = RefCount.build(stack, srefs);
- var.setValue(stack, NodeFactory.newRoot(Field.GENERIC_INT, 0));
- c_next.create(stack);
- RefCount.incRefs(drefs);
- next = (SingleValueChannel<Object>) c_next.get(stack);
- if (tracer.isEnabled()) {
- tracer.trace(thr, unwrap(next));
- }
- i++;
- case 1:
- while (true) {
- body.run(thr);
- if (next.isEmpty()) {
- // must do this twice since the closeDataSet calls
- // inside the iterate won't be called if the iterate
- // condition is true
- RefCount.decRefs(drefs);
- RefCount.decRefs(drefs);
- break;
- }
- else {
+ out:
+ while(true) {
+ switch(i) {
+ case 0:
+ drefs = RefCount.build(stack, srefs);
+ var.setValue(stack, NodeFactory.newRoot(Field.GENERIC_INT, 0));
+ c_next.create(stack);
RefCount.incRefs(drefs);
- }
- Object val = next.removeFirst();
- if (tracer.isEnabled()) {
- tracer.trace(thr, unwrap(next));
- }
- var.setValue(stack, val);
+ next = (SingleValueChannel<Object>) c_next.get(stack);
+ if (tracer.isEnabled()) {
+ tracer.trace(thr, unwrap(next));
+ }
+ i++;
+ case 1:
+ thr2 = thr.fork(new KRunnable() {
+ @Override
+ public void run(LWThread thr) {
+ body.run(thr);
+ }
+ });
+ i++;
+ thr2.start();
+ case 2:
+ thr2.waitFor();
+ if (next.isEmpty()) {
+ // must do this twice since the closeDataSet calls
+ // inside the iterate won't be called if the iterate
+ // condition is true
+ RefCount.decRefs(drefs);
+ RefCount.decRefs(drefs);
+ break out;
+ }
+ else {
+ RefCount.incRefs(drefs);
+ }
+ Object val = next.removeFirst();
+ if (tracer.isEnabled()) {
+ tracer.trace(thr, unwrap(next));
+ }
+ var.setValue(stack, val);
+ i = 1;
}
- }
+ }
}
catch (Yield y) {
+ y.getState().push(thr2);
y.getState().push(drefs);
y.getState().push(next);
y.getState().push(i);
More information about the Swift-commit
mailing list