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

Join Block Continuations

Chapter 3 skips some details of join blocks. This section introduces how to use the return values of statements inside a join block and by implementing message handlers which can receive the result of a join block.

A join block always returns an object array if it joins 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 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 receives the result of the join block.
 
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
Wei-Jen Wang
2007-11-28