Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is actor model in context of a programming language?

I've seen it mentioned in several places in contexts like Erlang actor model, Groovy actors, Scala actor model etc. What does this refer to?

like image 242
Vasil Avatar asked Mar 21 '09 13:03

Vasil


People also ask

What is the actor model in programming?

The actor model is a computer science concept that uses "actors" as the fundamental agents of computing. Actors take input, send output and perform functions. They can also create other actors.

Could you explain the actor model and what problem it solves?

Instead of calling methods, actors send messages to each other. Sending a message does not transfer the thread of execution from the sender to the destination. An actor can send a message and continue without blocking. It can, therefore, do more work, send and receive messages.

What is actor model good for?

The actor model abstraction allows you to think about your code in terms of communication, not unlike the exchanges that occur between people in a large organization. Use of actors allows us to: Enforce encapsulation without resorting to locks.

What is actor model in Erlang?

The actor model is a conceptual model to deal with concurrent computation. It defines some general rules for how the system's components should behave and interact with each other. The most famous language that uses this model is probably Erlang .


2 Answers

I think Wikipedia sums it up best:

The Actor model adopts the philosophy that everything is an actor. This is similar to the everything is an object philosophy used by some object-oriented programming languages, but differs in that object-oriented software is typically executed sequentially, while the Actor model is inherently concurrent. [snip] The Actor model is about the semantics of message passing.

like image 95
Andrew Hare Avatar answered Nov 11 '22 04:11

Andrew Hare


Some time ago I wrote this blog post that explains the basic concepts of the model and builds a basic implementation with JavaScript. From the post:

In the Actor Model, an actor is the foundation on which you build the structure of your application, it has internal state invisible to the outer world and interacts with other actors through asynchronous messages.

If this sounds to you a lot like Object-Oriented Programming (OOP), you are right. The Actor Model can be thought as OOP with special treatment to messages: they are delivered asynchronously and executed synchronously by the receiver.

Every actor is identified with a unique address by which you send messages to it. When a message is processed, it is matched against the current behavior of the actor; which is nothing more than a function that defines the actions to be taken in reaction to the message. In response to a message, an actor may:

  • Create more actors.
  • Send messages to other actors.
  • Designate internal state to handle the next message.
like image 36
roperzh Avatar answered Nov 11 '22 03:11

roperzh