Skip to content

Instantly share code, notes, and snippets.

@shibukawa
Created November 13, 2019 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibukawa/52fbd7791ffde23dea4fff7178a95373 to your computer and use it in GitHub Desktop.
Save shibukawa/52fbd7791ffde23dea4fff7178a95373 to your computer and use it in GitHub Desktop.
% go run -race test.go
==================
WARNING: DATA RACE
Write at 0x00c00009c000 by goroutine 7:
main.main.func2()
/Users/shibukawa/test.go:15 +0x7e
Previous write at 0x00c00009c000 by goroutine 6:
main.main.func1()
/Users/shibukawa/test.go:12 +0x7e
Goroutine 7 (running) created at:
main.main()
/Users/shibukawa/test.go:14 +0xfa
Goroutine 6 (finished) created at:
main.main()
/Users/shibukawa/test.go:11 +0xce
==================
Found 1 data race(s)
exit status 66
package main
import (
"time"
)
func main() {
var f bool
a := make(map[int]bool)
a[1] = true
go func() {
f = a[1]
}()
go func() {
f = a[1]
}()
time.Sleep(time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment