Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Goroutine analogues in other languages

Concurrency is really hard part of programming. Recent time goroutine is very popular. My question is - What kind of goroutine analogues exist in other languages?

like image 265
Doseke Avatar asked Dec 23 '16 05:12

Doseke


People also ask

What does Goroutine mean?

A goroutine is a function that executes simultaneously with other goroutines in a program and are lightweight threads managed by Go. A goroutine takes about 2kB of stack space to initialize.

Why is Goroutine cheaper than thread?

Goroutines are extremely cheap when compared to threads. They are only a few kb in stack size and the stack can grow and shrink according to needs of the application whereas in the case of threads the stack size has to be specified and is fixed. The Goroutines are multiplexed to fewer number of OS threads.

What is Goroutine and channel?

A goroutine is a function that runs independently of the function that started it. Sometimes Go developers explain a goroutine as a function that runs as if it were on its own thread. Channel is a pipeline for sending and receiving data. Think of it as a socket that runs inside your program.

Why are Goroutines better than threads?

Goroutines have easy communication medium known as channel. Thread does not have easy communication medium. Due to the presence of channel one goroutine can communicate with other goroutine with low latency. Due to lack of easy communication medium inter-threads communicate takes place with high latency.


1 Answers

goroutine are inspired by CSP (Communicating sequential processes), which is highly influential in the design of the occam programming language, and also influenced the design of programming languages such as Limbo, RaftLib, Go, and Crystal.

Note that goroutine are not without criticisms.

It differs from the Actor Model in that:

  • CSP processes are anonymous, while actors have identities.
  • CSP message-passing fundamentally involves a rendezvous between the processes involved in sending and receiving the message. In contrast, message-passing in actor systems is fundamentally asynchronous
  • CSP uses explicit channels for message passing, whereas actor systems transmit messages to named destination actors.
like image 144
VonC Avatar answered Sep 20 '22 00:09

VonC