Last active
February 9, 2017 05:41
-
-
Save rakyll/cebd362348cc3a0866c4 to your computer and use it in GitHub Desktop.
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 run main.go | |
fatal error: concurrent map writes | |
goroutine 34 [running]: | |
runtime.throw(0x89200, 0x15) | |
/Users/jbd/go/src/runtime/panic.go:530 +0x90 fp=0xc8200806d8 sp=0xc8200806c0 | |
runtime.mapassign1(0x5e940, 0xc8200161e0, 0xc8200807a0, 0xc8200807a0) | |
/Users/jbd/go/src/runtime/hashmap.go:445 +0xb1 fp=0xc820080780 sp=0xc8200806d8 | |
main.main.func1(0xc8200161e0, 0xc82000a170) | |
/Users/jbd/src/github.com/rakyll/experimental/maprace/main.go:11 +0x50 fp=0xc8200807b0 sp=0xc820080780 | |
runtime.goexit() | |
/Users/jbd/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc8200807b8 sp=0xc8200807b0 | |
created by main.main | |
/Users/jbd/src/github.com/rakyll/experimental/maprace/main.go:12 +0x9d | |
goroutine 1 [sleep]: | |
time.Sleep(0x3b9aca00) | |
/Users/jbd/go/src/runtime/time.go:59 +0xf9 | |
main.main() | |
/Users/jbd/src/github.com/rakyll/experimental/maprace/main.go:14 +0xc1 | |
exit status 2 |
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 "time" | |
const n = 50 | |
func main() { | |
m := make(map[int]struct{}, n) | |
for i := 0; i < n; i++ { | |
go func() { | |
m[i] = struct{}{} | |
}() | |
} | |
time.Sleep(time.Second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how is the race condition caught if you're not passing the -race flag ?