goroutines/

directory
v0.0.0-...-91b80fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2018 License: Apache-2.0

README

Goroutines

Goroutines are functions that are created and scheduled to be run independently by the Go scheduler. The Go scheduler is responsible for the management and execution of goroutines.

Notes

  • Goroutines are functions that are scheduled to run independently.
  • 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.

Design Guidelines

Diagrams

How the scheduler works.

Ardan Labs

Difference between concurrency and parallelism.

Ardan Labs

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
Explanation of the Scheduler
15 Years of Concurrency - Joe Duffy
How does the golang scheduler work? - Ian Lance Taylor

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 down from 100 to 0 and one that counts up from 0 to 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.

Directories

Path Synopsis
Sample program to show how to create goroutines and how the scheduler behaves.
Sample program to show how to create goroutines and how the scheduler behaves.
Sample program to show how the goroutine scheduler will time slice goroutines on a single thread.
Sample program to show how the goroutine scheduler will time slice goroutines on a single thread.
Sample program to show how to create goroutines and how the goroutine scheduler behaves with two contexts.
Sample program to show how to create goroutines and how the goroutine scheduler behaves with two contexts.
exercises
exercise1
Create a program that declares two anonymous functions.
Create a program that declares two anonymous functions.
template1
Create a program that declares two anonymous functions.
Create a program that declares two anonymous functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL