Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Memory consistency models" subsection to "Memory orderings" section #16

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yutingshih
Copy link

This pull request aims to enhance the comprehensiveness of the “Memory orderings” section of this book. Currently, the section primarily covers memory orders defined in C11/C++11 but lacks discussion on hardware assumptions regarding memory consistency. Thus I made the following changes:

  1. Reorganization
    • Moved the content originally under “Memory orderings” related to C11/C++11 atomics to a dedicated subsection titled “C11/C++ atomics” within the “Memory orderings” section.
  2. Addition
    • Introduced a new subsection titled “Memory consistency models”
      • Detailed descriptions of sequential consistency, x86 total store order, and ARM’s relaxed memory order.
      • Included schematic diagrams illustrating hardware architectures and litmus tests to aid readers’ comprehension.

concurrency-primer.tex Outdated Show resolved Hide resolved
y = 1; r2 = x;
\end{ccode}

If this program satisfies sequential consistency, then for Thread 1, \monobox{x = 1} must occur before \monobox{y = 1}, and for Thread 2, \monobox{r1 = y} must occur before \monobox{r2 = x}. For the entire program, the following six execution orders are possible:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use rich LaTeX annotations to represent the following.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean I should use \cc{...} or \cpp{...} instead of \monobox{...}?


\subsubsection{Total store order (TSO)}

Although sequential consistency is considered the "golden standard" for multi-threaded programs, its many constraints limit performance optimization. As a result, it is rarely implemented in modern processors. Instead, more relaxed memory models are used, such as the total store order (TSO) memory model adopted by the x86 architecture. One can envision the hardware roughly as follows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concurrency-primer.tex Outdated Show resolved Hide resolved
concurrency-primer.tex Outdated Show resolved Hide resolved
concurrency-primer.tex Outdated Show resolved Hide resolved
\subsection{Memory consistency models}

When a program is compiled and executed, it doesn't always follow the written order.
The system may change the sequence and optimize it to simulate line-by-line execution, as long as the final result matches the expected outcome.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should address the impact from modern microprocessors and optimizing compilers.

When a program is compiled and executed, it doesn't always follow the written order.
The system may change the sequence and optimize it to simulate line-by-line execution, as long as the final result matches the expected outcome.

This requires an agreement between the programmer and the system (hardware, compiler, etc.), ensuring that if the rules are followed, the execution will be correct.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge the statement into the previous paragraph.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest main branch.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of git merge, do git rebase.

1. split setences into separate lines
2. change the quotation marks "..." as ``...''
- Changed "doesn't" to "does not" for formal English writing
- Fixed the inconsistency of quotation marks
- Merged related statements into one paragraph

The write order seen by one thread can differ from the order seen by other threads because write operations can be reordered during propagation.
However, reads and writes to the same memory address must still follow a total order.
Therefore, the following litmus test cannot result in \monobox{r1 = 1}, \monobox{r2 = 2}, but \monobox{r3 = 2}, \monobox{r4 = 1}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide some information about running Litmus tests.


\subsubsection{Sequential consistency (SC)}

In the 1970s, Leslie Lamport proposed the most common memory consistency model, sequential consistency (SC), defined as follows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some references at the end of this document.

@jserv
Copy link
Contributor

jserv commented Aug 28, 2024

Any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants