tags : Computation and Computer Theory, Erlang
It is a mathematical model of concurrent computation that treats actor as the fundamental unit of computation. Actors usually come in systems.
What makes an Actor?
- Processing: Getting something done
- Storing: Ability to store/ use memory
- Communicating: Ability to communicate (have an address)
What can an Actor do?
- Create more actors.
- Send messages to actors that it knows.
- Designate how it will deal with the next message that is sent to itself.
- Eg. You have ā¹5 and someone sends you ā¹6 after sometime, so next time you need to do some transaction youāll be using ā¹11 and not ā¹5 as your balance.
š About running the tasks concurrently
- Conceptually, 1 message at a time
- But implementers can have concurrent implementations.
- Synchronization is built into the rule that 1 message is sent at a time.
Future
Future is a special actor, you can create an actor for any result while the result is being computed and you can keep passing that result around or store it.
Identity and Address
identity != address
- There can be one address for a whole bunch of actors
- One actor can have multiple addresses
We cannot tell if there is one actor or multiple actors behind a given address. All you can do with an address is send it a message. The integrity of addresses is to be maintained to ensure capability.
Communication
The communication happens directy(eg. put
,=get=); there is no channel involved. If in case you want to implement sequencing you can create futures
and send the sequence to the reciever actor and they later can manifest it if needed.
Messages gets delivered at most once. If you send 3 messages to the same actor, it will just execute one at a time. To have these 3 messages being executed concurrently, you need to create 3 actors and send one message to each.
Non-determinism and Indeterminism
- Nondeterministic: Nondeterministic Turing machines(NTM) have only bounded nondeterminism.
- Indeterminism: When things are decided based on how things worked out. Hewitt tries to justify unbounded non-determinism based on the idea of arbiters as you could not tell how long it would take the arbiter to make its decision.
š Arbiters
This is a theoretical concept for reasoning about actor programs.
Arbiters break ties. It is something you canāt make out of straight AND/OR gates or other boolean components.
- w/o arbiter: 2 inputs and 2 outputs
- input: i1,i2 will give output: o1, o2 in order
- we can predict the ordering
- w arbiter: 2 inputs and gives 1 only one output
- input: i1,i2 will give output: o2 or o2
- we cannot predict the ordering
This result is of considerable practical importance, as multiprocessor computers would not work reliably without it. The first multiprocessor computers date from the late 1960s, predating the development of reliable arbiters.
Erlang message passing say pretty much the same thing: whenever two processes send a message each to a third process, and there is no ordering constraint on the individual send events, you can never rely on which message will end up first in the receiverās mailbox.
FAQ
Programming Languages
There is an art to making programming languages for actors, very easy to screw it up. Erlang
is probably one of the most famous languages that uses Actor model.
Why we should not try to force consistency in our world
- We canāt
- We donāt know much and some of it is wrong. (schrodinger cat)