Golang concurrency
From wikinotes
This page is about the methods of concurrency provided by go.
If you're looking for synchronization primitives (ex. mutexes, semaphores, ... see golang synchronization)
Goroutines
Goroutines use green-threads rather than os-threads.
An OS thread is relatively expensive in setup and memory. One thread is reserved for a particular stack.
Go abstracts threads/threadpools with goroutines to make threads relatively cheap.func doThing() { fmt.Println("hi") } func main() { go sayHello() // <-- run in thread }Go functions default to using value objects rather than references.
Depending on your datastructure, this makes goroutines fairly concurrency-safe, since it operates on a copy of the data, rather than the same data.func printThing(a string) { fmt.Println(a) } go printThing("abc")