Async-Finish Parallelism

The async and finish statements are high-level constructs for creating and terminating threads.

Async

async is a construct for executing a statement in parallel as a new activity. The basic form of async is async S. The statement async S creates an activity to execute a statement. A new child activity is executed in the same place as the parent activity.

Finish

finish is a construct for global termination of a statement and all the activities that it has generated. The basic form of finish is finish S. The statement finish S converts global termination to local termination. Finish S waits for termination of all async statement bodies started while executing S.

Local and Global Termination

Example

public class AsyncFinish1 {
  public static def main(args: Array[String]) {
  val n = 100;    		  		
  var evenSum:Int = 0;
  var oddSum:Int = 0;
  var i:Int;
  var j:Int;
		
  finish {                  			
  async { 
  for (i = 2 ; i <= n ; i += 2) 
  evenSum = i;
  Console.OUT.println("evenSum = " + evenSum);
  }
			
  async { 
  for ( j = 1; j <= n; j += 2)
  oddSum = j;  
  Console.OUT.println("oddSum = " + oddSum);
  }    			   	    
  }	
 } 
}

Rooted Exception Handling

The async/finish environment is a model for rooted exception handling. The finish construct is a collection point for exceptions thrown by activities executed within the finish enclosing block. For more information, see the Rooted Exception Model topic.

Related information
Async
Finish
Exceptions
Rooted Exception Model