how recover runtime panic on "concurrent map read , map write"? usual defer recover doesn't seem work. why that?
i know not supposed use maps in concurrent contexts, still: how recover here?
example:
package main import "time" var m = make(map[string]string) func main() { go func() { { m["x"] = "foo" } }() go func() { { m["x"] = "foo" } }() time.sleep(1 * time.second) }
please add recovery code. :)
recovering doesn't work here because experience not panicing state.
go 1.6 added lightweight concurrent misuse of maps detection runtime:
the runtime has added lightweight, best-effort detection of concurrent misuse of maps. always, if 1 goroutine writing map, no other goroutine should reading or writing map concurrently. if runtime detects condition, prints diagnosis , crashes program. best way find out more problem run program under race detector, more reliably identify race , give more detail.
what experience intentional crash runtime, it's not result of panic()
call recover()
call in deferred function stop.
there's nothing can stop except prevent concurrent misuse of maps. if leave app , wouldn't crash, experience mysterious, undefined behavior @ runtime.
Comments
Post a Comment