Skip to content

Instantly share code, notes, and snippets.

@ash2k
Created March 11, 2016 12:06
Show Gist options
  • Save ash2k/78d639494751d71b25ef to your computer and use it in GitHub Desktop.
Save ash2k/78d639494751d71b25ef to your computer and use it in GitHub Desktop.
Safe concurrent reads
package main
import (
"fmt"
)
func main() {
x := make(map[string]int)
x["abc"] = 1
for i := 0; i < 10; i++ {
go func() {
c := x["abc"]
fmt.Println(c)
}()
}
}
$ go build --race ./no_race.go
$ ./no_race
1
1
1
1
1
1
1
1
1
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment