synchronization in Go
There are various ways to do synchronisation in Go, the most common approach is to use a mutex. ``` package main import ( "fmt" "sync" "time" ) var ( counter = 0 lock sync.Mutex ) func main() { for i := 0; i < 20; i++ { go incr() } time.Sleep(time.Millisecond * 10) fmt.Println(counter) } func incr() { lock.Lock() defer lock.Unlock() counter++ fmt.Println(counter) } ```