next up previous contents
Next: Message Properties Up: Advanced Concurrency Coordination Previous: Named Tokens   Contents

Join Continuations

Chapter 3 skips some important issues of join block continuations. In this section, we are going to introduce how to use the join block return values and how to implement the join block reception handler.

A join block always returns an object array if it does join several messages to a reserved keyword token, or a named token. If those message handlers to be joined do not return (void type return), or the return values are ignored, the join block functions like a barrier for parallel message processing.

The named token can be applied to the join block as follows:
 
1. token x = join {
2.    a<-m1();
3.    b<-m2();
4. };
 
   
The return value of the join block is received by the join block reception handler. Every join block reception handler must have only one argument with the type of the object array. The following example illustrates how to access the join block return values through tokens. In lines 16-20, the message multiply will not be processed until the three messages add(2,3), add(3,4), and add(2,4) are processed. The token passed to multiply is an array of Integers generated by the three adds messages. The message handler multiply(Object numbers[]) in lines 3-7 is the join block reception handler.
 
1. behavior JoinContinuation {
2.
3.   int multiply(Object numbers[]){
4.     return ((Integer)numbers[0]).intValue() * 
5.            ((Integer)numbers[1]).intValue() * 
6.            ((Integer)numbers[2]).intValue();
7.   }
8.
9.   int add(int n1, int n2) {
10.    return n1 + n2;
11.  }
12.
13.  void act(String args[]) {
14.
15.    standardOutput<-print("Value: ") @ 
16.    join {
17.      add(2,3);
18.      add(3,4);
19.      add(2,4);
20.    } @ multiply( token ) @ standardOutput<-println( token );
21.  }
22.
23.}
 
   


next up previous contents
Next: Message Properties Up: Advanced Concurrency Coordination Previous: Named Tokens   Contents
Wei-Jen Wang 2005-10-24