【Golang】Go Memory Model

Posted by 西维蜀黍 on 2021-06-30, Last Modified on 2021-10-17

Background

Consistency Model

Sequential Consitency

The sequential consistency model was proposed by Lamport(1979). It is a weaker memory model than strict consistency model. A write to a variable does not have to be seen instantaneously, however, writes to variables by different processors have to be seen in the same order by all processors. As defined by Lamport(1979),[4] sequential consistency is met if “the result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program.”

Example

// Thread 1
x = 1
y = 1

// Thread 2
r1 = y
r2 = x

Thread 1’s writes are observed by other threads in original order.

Reference