next up previous contents
Next: Coordinating Concurrency Up: Writing Concurrent Programs Previous: Actor Creation   Contents

Message Passing

To achieve more parallelism, SALSA uses message passing. A SALSA method is named a message handler.

Message passing in SALSA is implemented by asynchronous message delivery with dynamic method invocation. The following example shows how an actor sends a message to itself. Note that it is not a JAVA method invocation:
 
handler();  // equivalent to "self <- handler();"
 
   
Another type of message passing statement requires a target (an actor reference), a reserved key word <-, and a message handler with arguments to be sent. For instance, an actor can send a message to the standardOutput actor as follows:
 
// send a method println() with an argument "Hello World", 
// to the actor standardOutput.
standardOutput <- println("Hello World"); 
 
   
Note that the following expression is illegal because it is neither a JAVA method invocation nor a message passing:
 
// Wrong! It does not compile!!!
self <- someObject.someHandler();
 
   
To avoid unexpected race conditions by accessing the passed arguments, messages of SALSA enforces pass-by-value for every object, and pass-by-reference for every actor. Any object passed as an argument is cloned at the moment it is sent, and the cloned object is then sent to the target actor.


next up previous contents
Next: Coordinating Concurrency Up: Writing Concurrent Programs Previous: Actor Creation   Contents
Wei-Jen Wang 2005-10-24