User Tools

Site Tools


at:tutorial:actors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
at:tutorial:actors [2007/04/01 11:46] – added tvcutsemat:tutorial:actors [2007/04/01 12:05] – added tvcutsem
Line 22: Line 22:
  
 <code> <code>
-def a := actor: {+>def a := actor: {
   def sayHello() {   def sayHello() {
     system.println("Hello World")     system.println("Hello World")
   };   };
 }; };
 +>><far ref to:<object:1555668>>
 </code> </code>
 +
 +As you can see, actors are created similar to objects. The ''actor:'' method, defined in the global lexical scope, takes a closure as its sole argument and uses that closure to initialize the behaviour of the new actor. The creator of the actor immediately receives a so-called //far reference// to this behaviour object, and from that moment on the creating actor and the created actor run in parallel, each capable of processing incoming messages autonomously.
 +
 +So what exactly is a far reference to an object? The terminology stems from the E language: it is an object reference that refers to an object hosted by another actor. The main difference between regular object references and far references is that regular references allow direct, synchronous access to an object, while far references disallow such access. This is enforced by the kind of messages that these references can carry, as will be explained below.
  
 === Asynchronous Message Sending === === Asynchronous Message Sending ===
 +
 +AmbientTalk, like E, lexically distinguishes between synchronous method invocation and asynchronous message sending. The former is expressed as ''o.m()'' while the latter is expressed as ''o<-m()''. Regular object references can carry both kinds of invocations. Synchronous method invocation behaves as in any typical object-oriented language. When an asynchronous message is sent to a local object ("local" meaning "hosted by the same actor"), the message is enqueued in the actor's own message queue and the method invocation will be executed at a later point in time.
 +
 +Far references, like the reference stored in the variable ''a'' above, only carry asynchronous message sends, and as such totally decouple the objects in different actors in time: objects can //never// be blocked waiting for an outstanding remote procedure call, they can only communicate by means of purely //asynchronous// message passing. This is a key property of AmbientTalk's concurrency model, and it is a crucial property in the context of [[distribution|distributed programming]].
 +
 +Hence, given the example above, the method ''sayHello'' can only be invoked as follows given a far reference ''a'':
 +
 +<code>
 +>a<-sayHello();
 +>>nil
 +</code>
 +
 +async messages, parameter passing, futures
  
 === Isolates === === Isolates ===
 +
 +isolate stripe, by-copy, scoping rules, no external method defs
  
 === Actor Mirrors === === Actor Mirrors ===
 +
 +explain: mirror factory, message creation, message sending, install
 +
 +=== Nesting Actors ===
 +
 +lexical scoping rules for nested actors
at/tutorial/actors.txt · Last modified: 2020/02/05 21:26 by elisag