Created
June 8, 2017 21:16
-
-
Save aaronlehmann/281681d458e30e1d9b4637952f22793a to your computer and use it in GitHub Desktop.
Concurrent map panic can't be recovered
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 | |
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