CSE224 - Go Concurrent Programming
Introduction
Go Routines
Traditionally, people used OS-level threads for concurrency, but threads are heavyweight. Go introduced goroutines, which are:
- Very cheap in terms of memory
- Managed by the Go runtime, not the OS
- Can be created in large numbers
Channel
A channel is a way for goroutines to communicate and synchronize with each other. It's like a pipe.
ch := make(chan string)
go func() {
ch <- "hello"
}()
msg := <-ch
fmt.Println(msg) // prints: hello
Comments