ch9/ch9-04 #186
ch9/ch9-04
#186
Replies: 4 comments
-
这里后面写的这么复杂,反而不知道在说啥。其实就是因为多核cpu中,并发运行时,在编译器编译后x,y变量有可能是在两个独立的CPU上都有副本的,并且此时是被初始化为0的,再之后,由于编译器认为A1,A2这两条语句和B1,B2这两条语句的顺序不影响结果,就有可能调换两者的次序。从而打印出x:0 y:0,y:0 x:0 |
Beta Was this translation helpful? Give feedback.
0 replies
-
这里可以去看看golang的内存模型 |
Beta Was this translation helpful? Give feedback.
0 replies
-
听着有些像Java的可见性与 |
Beta Was this translation helpful? Give feedback.
0 replies
-
也就是说,即使在 goroutine A 中已经执行了 A1,A2,但 goroutine B 未必能感知到 A1 已经执行了,它可能还是会输出它所在的 CPU 核心缓存中的值: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
ch9/ch9-04
中文版
https://golang-china.github.io/gopl-zh/ch9/ch9-04.html
Beta Was this translation helpful? Give feedback.
All reactions