예제 #1
0
 @Override
 public void run(LWThread thr) {
   int state = thr.checkSliceAndPopState(2);
   Stack stack = thr.getStack();
   ThreadSet ts = (ThreadSet) thr.popState();
   int fc = thr.popIntState();
   try {
     switch (state) {
       case 0:
         fc = stack.frameCount();
         state++;
       case 1:
         final ThreadSet tsf = new ThreadSet();
         ts = tsf;
         final int fcf = fc;
         int ec = childCount();
         for (int i = 0; i < ec; i++) {
           final int fi = i;
           LWThread ct =
               thr.fork(
                   new KRunnable() {
                     @Override
                     public void run(LWThread thr) {
                       try {
                         runChild(fi, thr);
                         tsf.threadDone(thr, null);
                       } catch (ExecutionException e) {
                         Stack stack = thr.getStack();
                         stack.dropToFrame(fcf);
                         tsf.threadDone(thr, e);
                         tsf.abortAll();
                       } catch (RuntimeException e) {
                         Stack stack = thr.getStack();
                         stack.dropToFrame(fcf);
                         tsf.threadDone(thr, new ExecutionException(Parallel.this, e));
                         tsf.abortAll();
                       }
                     }
                   });
           tsf.add(ct);
           initializeBuffers(i, stack);
         }
         ts.startAll();
         state++;
       default:
         ts.waitFor();
     }
   } catch (Yield y) {
     y.getState().push(fc);
     y.getState().push(ts);
     y.getState().push(state, 2);
     throw y;
   }
 }
예제 #2
0
 @Override
 protected void runBody(LWThread thr) {
   int i = thr.checkSliceAndPopState(1);
   try {
     switch (i) {
       case 0:
         remove(thr.getStack());
         i++;
       default:
         body.run(thr);
     }
   } catch (Yield y) {
     y.getState().push(i, 1);
     throw y;
   }
 }