To add to Bakul's description: A key difference in an actor-inspired model compared to a CSP-inspired one is that identity is subtly different. In Go, channels have identity and can be referenced. They can have multiple readers and writers. In Erlang, it is processes who has identity and you can send messages to processes. There can be multiple senders to the process, but only one process ever receives from the mailbox. This difference yields subtle differences in the way you often construct communication, but do note that the models are somewhat interchangable and what is written in one can be written in the other. Another subtlety is that multi-writer/single-reader can be targeted for optimization, and so on.
However, Erlang's message communication is not an implementation of the Actor model. According to Robert Virding, one of the Erlang authors, they didn't know about the actor model when they wrote the language, so if overlap is entirely by accident. Furthermore, Carl Hewitt who proposed the actor model has a paper in which he explains why Erlang doesn't implement it: in a pure actor system, you must be able to detect (groups of) processes who can make no progress ever and garbage collect them. Erlang doesn't do that. Erlang's message communication is buffered. Locally, there is no bound on the message buffer and it is up to the programmer to write appropriate flow control. Across nodes, connections are by TCP and thus are limited by the usual TCP window which acts like a buffer: a sender who sends a message on a 0-window condition is blocked until the delivery can happen. Crucially, Erlang relies on buffering for its implementation of a selective receive. You can set up a matching pattern and the mailbox will be searched, chronologically, until a message in the mailbox matches said pattern. If no message matches, the process is blocked until one does, or a timeout. When a process has identity, you can monitor its lifetime. This is a central concept in Erlang systems: monitors (or links) are set up between processes and when they terminate, other processes will have a message delivered to their mailbox and can thus take action on the event. In Go, there is no way to find the identity of a goroutine, which yields a different programming model. Process trees are handled by the "context" package and lifetime is communicated through a specially constructed "Done" channel. On Sun, Mar 4, 2018 at 10:31 PM Bakul Shah <ba...@bitblocks.com> wrote: > Messages get sent to an actor's address and only that actor “reads” > from that mailbox. And there is no buffering. Channels don’t run any > logic (like an actor), they may be buffered and any goroutine with > access to a channel may read from it. All goroutines run in the same > address space. As actors don’t share memory, they can be distributed > or can even migrate from one node to another. Erlang is an actor > language. Go is not. > > On Mar 4, 2018, at 9:00 AM, Anto Aravinth <anto.aravinth....@gmail.com> > wrote: > > Hello All, > > I'm new to golang and trying to understand the difference between channels > and actors. From my knowledge: > > 1. Golang support channels, which is concurrently safe > 2. Channels can be shared across goroutines that are running. (very much > similar to messages) > > Actors: > 1. They are based on messages. > 2. Messages are immutable by nature. > 3. Actors work based on messages, concurrently. > > I find actors and channels much similar, may be I'm wrong here. Any help > would be really good. > > Thanks, > Anto; > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.