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


Message Passing

SALSA actors use asynchronous message passing as their basic form of communication. A SALSA message handler is similar to a Java method. 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 token <-, 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 message 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 expression:
 
// Wrong! It does not compile!!!
// Assume 'a' is an actor reference.
a <- someObject.someHandler();
 
   
Message Passing in SALSA is by-value for objects, and by-reference for actors. 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
Wei-Jen Wang
2007-11-28