Skip to content

Instantly share code, notes, and snippets.

@rakyll rakyll/main.go
Last active Feb 9, 2017

Embed
What would you like to do?
$ 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
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)
}
@yanpozka

This comment has been minimized.

Copy link

commented Feb 9, 2017

how is the race condition caught if you're not passing the -race flag ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.