First look at a piece of code, which is an example of the Go Memory model article
?
var a, b int
?
Func f () {
???? A = 1
???? b = 2
}
Func g () {
???? Print (b)
???? Print (a)
}
Func Main () {
???? Go f ()
???? G ()
}
?
In fact, we need to say two points:
First: The statements within the function f may be executed in a random order, due to compiler optimizations, since the two statements do not have any dependencies on the inside of the function, which the compiler can do to improve operational efficiency
Second: This article says that the more radical compiler might delete the two statements of A=1 b=2 because it looks completely useless. From the local point of view it seems like this, but A and B are global variables, so aggressive appropriate? Maybe it's just a talk.
?
The meaning of the article is very clear, if there is a dependency, then explicitly write it out, otherwise the compiler does not know Ah!
Sync model for Go