Golang concurrency

From wikinotes
Revision as of 17:32, 6 June 2022 by Will (talk | contribs) (Created page with "= Goroutines = <blockquote> Goroutines use green-threads rather than os-threads.<br> An OS thread is relatively expensive in setup and memory. One thread is reserved for a par...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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
}

Threading

Multiprocessing