Go - Goroutine (concurrent function execution)

Card Puncher Data Processing

About

A goroutine is a concurrent function execution. A channel is a communication mechanism that allows one goroutine to pass values of a specified type to another goroutine.

The function main runs in a goroutine and the go statement creates additional goroutines.

When one goroutine attempts a send or receive on a channel, it blocks until another goroutine attempts the corresponding receive or send operation, at which point the value is transferred and both goroutines proceed.

Management

  • To sends a value on the channel ch (ch <- expression)
  • To receives all of them (<-ch).

Having main do all the printing ensures that output from each goroutine is processed as a unit, with no danger of interleaving if two goroutines finish at the same time.

Documentation / Reference





Discover More
Card Puncher Data Processing
Go - Channel

A channel is a communication mechanism that allows one goroutine to pass values of a specified type to another goroutine. To sends a value on the channel ch (ch <- expression) To receives all...
Card Puncher Data Processing
Go - Concurrency

Go concurrency is build on Communicating_sequential_processes - Tony Hoare’s CSP...



Share this page:
Follow us:
Task Runner