at:tutorial:actors
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:actors [2007/04/01 11:04] – created tvcutsem | at:tutorial:actors [2007/04/01 12:05] – added tvcutsem | ||
---|---|---|---|
Line 1: | Line 1: | ||
< | < | ||
- | ==== Concurrent Programming with Actors ==== | + | ===== Concurrent Programming with Actors ===== |
+ | |||
+ | Concurrency is an integral part of the AmbientTalk programming language. Rather than relying on [[wp> | ||
+ | |||
+ | === Threads vs Actors === | ||
+ | |||
+ | In traditional programming languages, the control flow of a concurrent program is divided over a number of threads. Each thread operates concurrently and control can switch from one thread to another non-deterministically. If two threads have access to the same data (objects), they might cause erroneous behaviour (so-called //race conditions// | ||
+ | |||
+ | The advantages of the thread-based model are that the model itself is easy to understand, it is efficiently implementable and it can be used to create very fine-grained synchronization (e.g. [[wp> | ||
+ | |||
+ | The original [[wp> | ||
+ | |||
+ | Generally speaking, an active object is an object that encapsulates its own thread of control. An active object also has a message queue or mailbox from which it processes incoming messages. Each message is processed sequentially. An active object responds to an incoming message by invoking the method corresponding to the message. The method is executed by the active object' | ||
=== Actors and Far References === | === Actors and Far References === | ||
+ | |||
+ | In AmbientTalk, | ||
+ | |||
+ | When an actor is created, it hosts a single object which is said to be the actor' | ||
+ | |||
+ | < | ||
+ | >def a := actor: { | ||
+ | def sayHello() { | ||
+ | system.println(" | ||
+ | }; | ||
+ | }; | ||
+ | >>< | ||
+ | </ | ||
+ | |||
+ | As you can see, actors are created similar to objects. The '' | ||
+ | |||
+ | 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, | ||
+ | |||
+ | Far references, like the reference stored in the variable '' | ||
+ | |||
+ | Hence, given the example above, the method '' | ||
+ | |||
+ | < | ||
+ | > | ||
+ | >>nil | ||
+ | </ | ||
+ | |||
+ | 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