Skip to content

Instantly share code, notes, and snippets.

@aaronlehmann
Created June 8, 2017 21:16
Show Gist options
  • Save aaronlehmann/281681d458e30e1d9b4637952f22793a to your computer and use it in GitHub Desktop.
Save aaronlehmann/281681d458e30e1d9b4637952f22793a to your computer and use it in GitHub Desktop.
Concurrent map panic can't be recovered
package main
var (
m = map[int]string{}
)
func readMap() {
defer func() {
recover()
}()
for key := range m {
_ = m[key]
}
}
func writeMap() {
for i := 0; i != 10000; i++ {
m[i] = "str"
}
}
func main() {
go func() {
for {
readMap()
}
}()
for {
writeMap()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment