How to recover from concurrent map writes?
问题 How do you recover from a runtime panic on a "concurrent map read and map write"? The usual defer with recover doesn't seem to work. Why is that? I know that you are not supposed to use maps in concurrent contexts, but still: how to recover here? Example: package main import "time" var m = make(map[string]string) func main() { go func() { for { m["x"] = "foo" } }() go func() { for { m["x"] = "foo" } }() time.Sleep(1 * time.Second) } Please add recovery code. :) 回答1: Recovering doesn't work