不能並發寫的原因
- 元素丟失 // TODO
- 破壞map的結構 // TODO
sync.Map相比RWLock在哪些點減少了加鎖的粒度,應該就是上述2點 // TODO
sync.Map的原理應該就是減小了鎖的粒度, 如果寫操作既不會造成元素丟失,也不會破壞map結構,就不需要加鎖,這就可以減小鎖的粒度。
sync.Map的原理不是讀寫分離嗎??? // TODO
map並發寫會報panic或fatal(調用panic包的throw函數)
panic可以被recover捕獲,但是fatal卻不能被捕獲,只能修改程序。
- 如果使用的第三方庫有fatal問題,只能讓庫的作者修改或者自己修改后使用該庫。
附錄1
I think JimB is the best answer here. If you have an external library throwing this error, you need to
A - Send a PR against that library to fix it. B - Create your own version of the library with no errors.
I strongly suggest that, before you integrate any external libraries in your code, you test it with Unit tests and Benchmarks to check if it is a deployable lib.