C ++ & memory consistency Model

Source: Internet
Author: User

One of the most important features of C ++ 11 is to add multi-threaded support and define the C ++ memory model. The memory model defines how memory operations on a processor are observed by other processes,

The memory model, or memory consistency model, specifies the values that a shared variable read in a multithreaded program is allowed to return.


The above definition comes from the foundation of C ++ memory model.

Below I have collected some relevant information I found during my recent studies for your reference:

1. http://herbsutter.com/2013/02/11/atomic-weapons-the-c-memory-model-and-modern-hardware/

There are two videos describing the atomic and sequential consistency of C ++.

2. Foundation of C ++ Memory Model

Defines the Memory Model of C ++

3. http://cs.gmu.edu/cne/modules/dsm/green/memcohe.html

Http://regal.csep.umflint.edu /~ Swturner/classes/csc577/online/chapter06/im1_6.html

Http://www.cs.nmsu.edu /~ Pfeiffer/classes/573/Notes/consistency.html

Www.cs.cmu.edu /~ Srini/15-446/S09/lectures/10-consistencyures

Definition of some memory models

4. http://en.wikipedia.org/wiki/Sequential_consistency

Sequential consistency definition

Here I will summarize sequential consistency (SC ). The initial definition of SC is shown in Figure 4 above, as follows:

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


The meaning here can be understood as that all read/write operations have a total order (full order), and read write on each processor is a sub-sequence of this full order, it is executed according to the program Order (this can be understood as the sequenced before relation defined in C ++ 11 ). Simply put, all the modifications seen by the processors must be consistent, that is, the following operations (a) are legal, and (B) are illegal.


Here, PX represents different processors, and from left to right represents the chronological order. (A) it is legal because P3 and P4 read the same modification, that is, B> A, but not in (B.

Some people may ask why B> A, not B> B, since SC is irrelevant to time, the definition only says that all RW has a total order, that is, the total order below is valid,

W (x) B [P1]> r (x) B [P3]> r (x) B [P4]> W (x) A [P1]> r (X) A [P3]> r (x) A [P4]


Time-related consisitency model, including strict consistency and linearizability.

C ++'s sequential consistency model is only guaranteed when the atomic and mutex of seq_cst are used. However, C ++ also provides the release consistency, that is, the acquire/release operation for synchronization, after correct use, it will provide a guarantee similar to sequential consistency, but the difference is that sequential consistency is global and valid for all operations, but acquire/release is only valid for a certain atomic object.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.