Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 2.3 KB

README.md

File metadata and controls

51 lines (34 loc) · 2.3 KB

Goroutines

Goroutines are functions that are created and scheduled to be run independently. Goroutines are multiplexed against a shared thread that is owned by logical processor. The scheduler is responsible for the management and execution of goroutines.

Notes

  • Goroutines are functions that are scheduled to run independently.
  • The scheduler uses a logical processor that owns an OS thread and goroutine run queue.
  • We must always maintain an account of running goroutines and shutdown cleanly.
  • Concurrency is not parallelism.
    • Concurrency is about dealing with lots of things at once.
    • Parallelism is about doing lots of things at once.

Diagrams

How the scheduler works.

Ardan Labs

Difference between concurrency and parallelism.

Ardan Labs

Links

http://blog.golang.org/advanced-go-concurrency-patterns
http://blog.golang.org/context
http://blog.golang.org/concurrency-is-not-parallelism
http://talks.golang.org/2013/distsys.slide
Go 1.5 GOMAXPROCS Default
http://www.goinggo.net/2014/01/concurrency-goroutines-and-gomaxprocs.html
The Linux Scheduler: a Decade of Wasted Cores

Code Review

Goroutines and concurrency (Go Playground)
Goroutine time slicing (Go Playground)
Goroutines and parallelism (Go Playground)

Exercises

Exercise 1

Part A Create a program that declares two anonymous functions. One that counts up to 100 from 0 and one that counts down to 0 from 100. Display each number with an unique identifier for each goroutine. Then create goroutines from these functions and don't let main return until the goroutines complete.

Part B Run the program in parallel.

Template (Go Playground) | Answer (Go Playground)


All material is licensed under the Apache License Version 2.0, January 2004.