感谢 OP 发的帖子
感谢大佬提供的文章
https://juejin.cn/post/6911126210340716558https://www.51cto.com/article/716546.htmlhttps://fanlv.fun/2020/06/09/golang-memory-model/刚好无聊学学 golang ,学了很多知识点
golang 实现了 Happens Before 语义的几个地方 init 函数、goruntine 的创建、goruntine 的销毁、channel 通讯、锁、sync 、sync/atomic
LOCK prefix 和 XCHG 指令前缀提供了强一致性的内(缓)存读写保证,Mutex 锁基于 Atomic 来实现 Happens Before 语义,Atomic 的 PI 对应了这些汇编指令
引用 3.2 Golang Happen Before 语义继承图,贴近来有点乱,来自
https://fanlv.fun/2020/06/09/golang-memory-model/ +----------+ +-----------+ +---------+
| sync.Map | | sync.Once | | channel |
++---------+++---------+-+ +----+----+
| | | |
| | | |
+------------+ | +-----------------+ | |
| | | | +v--------+ | |
| WaitGroup +---+ | RwLock| Mutex | | +------v-------+
+------------+ | +-------+---------+ | | runtime lock |
| | +------+-------+
| | |
| | |
| | |
+------+v---------------------v +------v-------+
| LOAD | other atomic action | |runtime atomic|
+------+--------------+-------+ +------+-------+
| |
| |
+------------v------------------v+
| LOCK prefix |
+--------------------------------+