ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/BinaryAsyncAction.java
(Generate patch)

Comparing jsr166/src/test/loops/BinaryAsyncAction.java (file contents):
Revision 1.3 by jsr166, Mon Sep 20 20:45:38 2010 UTC vs.
Revision 1.11 by jsr166, Mon Nov 26 05:59:05 2012 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < *
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import java.util.concurrent.*;
# Line 15 | Line 15 | import java.util.concurrent.atomic.*;
15   * BinaryAsyncActions are simpler to use and have less overhead in
16   * typical uasges but are restricted to binary computation trees.
17   *
18 < * <p> Upon construction, an BinaryAsyncAction does not bear any
18 > * <p>Upon construction, a BinaryAsyncAction does not bear any
19   * linkages. For non-root tasks, links must be established using
20   * method <tt>linkSubtasks</tt> before use.
21   *
22 < * <p> <b>Sample Usage.</b>  A version of Fibonacci:
22 > * <p><b>Sample Usage.</b>  A version of Fibonacci:
23   * <pre>
24   * class Fib extends BinaryAsyncAction {
25   *   final int n;
# Line 27 | Line 27 | import java.util.concurrent.atomic.*;
27   *   Fib(int n) { this.n = n; }
28   *   protected void compute() {
29   *     if (n &gt; 1) {
30 < *        linkAndForkSubtasks(new Fib(n-1), new Fib(n-2));
30 > *       linkAndForkSubtasks(new Fib(n-1), new Fib(n-2));
31   *     else {
32 < *        result = n; // fib(0)==0; fib(1)==1
33 < *        complete();
32 > *       result = n; // fib(0)==0; fib(1)==1
33 > *       complete();
34   *     }
35   *   }
36   *   protected void onComplete(BinaryAsyncAction x, BinaryAsyncAction y) {
37 < *      result = ((Fib)x).result + ((Fib)y).result;
37 > *     result = ((Fib)x).result + ((Fib)y).result;
38   *   }
39   * }
40   * </pre>
# Line 44 | Line 44 | import java.util.concurrent.atomic.*;
44   *   protected void compute() {
45   *     Fib f = this;
46   *     while (f.n &gt; 1) {
47 < *        Fib left = new Fib(f.n - 1);
48 < *        Fib right = new Fib(f.n - 2);
49 < *        f.linkSubtasks(left, right);
50 < *        right.fork(); // fork right
51 < *        f = left;     // loop on left
47 > *       Fib left = new Fib(f.n - 1);
48 > *       Fib right = new Fib(f.n - 2);
49 > *       f.linkSubtasks(left, right);
50 > *       right.fork(); // fork right
51 > *       f = left;     // loop on left
52   *     }
53   *     f.result = f.n;
54   *     f.complete();
# Line 101 | Line 101 | public abstract class BinaryAsyncAction
101       * Overridable callback action triggered upon <tt>complete</tt> of
102       * subtasks.  Upon invocation, both subtasks have completed.
103       * After return, this task <tt>isDone</tt> and is joinable by
104 <     * other tasks. The default version of this method does
105 <     * nothing. But it may may be overridden in subclasses to perform
106 <     * some action (for example a reduction) when this task is
107 <     * completes.
104 >     * other tasks. The default version of this method does nothing.
105 >     * But it may be overridden in subclasses to perform some action
106 >     * (for example a reduction) when this task is completes.
107       * @param x one subtask
108       * @param y the other subtask
109       */
# Line 121 | Line 120 | public abstract class BinaryAsyncAction
120       * default version of this method does nothing and returns
121       * <tt>true</tt>.
122       * @return true if this task's exception should be propagated to
123 <     * this tasks parent.
123 >     * this task's parent.
124       */
125      protected boolean onException() {
126          return true;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines