Created
March 11, 2016 12:06
-
-
Save ash2k/78d639494751d71b25ef to your computer and use it in GitHub Desktop.
Safe concurrent reads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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