Esempio n. 1
0
        /// <summary> Fork all tasks in array, and await their completion.
        /// Behaviorally equivalent to:
        /// <pre>
        /// for (int i = 0; i &lt; tasks.length; ++i) tasks[i].fork();
        /// for (int i = 0; i &lt; tasks.length; ++i) tasks[i].join();
        /// </pre>
        ///
        /// </summary>

        public void  CoInvoke(FJTask[] tasks)
        {
            FJTaskRunner.coInvoke(tasks);
        }
Esempio n. 2
0
 /// <summary> Fork both tasks and then wait for their completion. It behaves as:
 /// <pre>
 /// task1.fork(); task2.fork(); task2.join(); task1.join();
 /// </pre>
 /// As a simple classic example, here is
 /// a class that computes the Fibonacci function:
 /// <pre>
 /// public class Fib extends FJTask {
 ///
 /// // Computes fibonacci(n) = fibonacci(n-1) + fibonacci(n-2);  for n> 1
 /// //          fibonacci(0) = 0;
 /// //          fibonacci(1) = 1.
 ///
 /// // Value to compute fibonacci function for.
 /// // It is replaced with the answer when computed.
 /// private volatile int number;
 ///
 /// public Fib(int n) { number = n; }
 ///
 /// public int getAnswer() {
 /// if (!isDone()) throw new Error("Not yet computed");
 /// return number;
 /// }
 ///
 /// public void run() {
 /// int n = number;
 /// if (n > 1) {
 /// Fib f1 = new Fib(n - 1);
 /// Fib f2 = new Fib(n - 2);
 ///
 /// coInvoke(f1, f2); // run these in parallel
 ///
 /// // we know f1 and f2 are computed, so just directly access numbers
 /// number = f1.number + f2.number;
 /// }
 /// }
 ///
 /// public static void main(String[] args) { // sample driver
 /// try {
 /// int groupSize = 2;    // 2 worker threads
 /// int num = 35;         // compute fib(35)
 /// FJTaskRunnerGroup group = new FJTaskRunnerGroup(groupSize);
 /// Fib f = new Fib(num);
 /// group.invoke(f);
 /// int result = f.getAnswer();
 /// System.out.println(" Answer: " + result);
 /// }
 /// catch (InterruptedException ex) {
 /// System.out.println("Interrupted");
 /// }
 /// }
 /// }
 /// </pre>
 ///
 /// </summary>
 public void  CoInvoke(FJTask task1, FJTask task2)
 {
     FJTaskRunner.coInvoke(task1, task2);
 }