\documentclass[11pt]{article}

\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{a4paper}

\usepackage{verbatim}
\usepackage{hyperref}
\usepackage{amsmath}

\title{HW1 -- Memory Model Outcomes}
\author{CS 554, Fall 2025\\ Due Sep. 5}
\date{}

\begin{document}
\maketitle
\section{Glossary}
\begin{itemize}
\item Sequential consistency (SC) is a memory model in which all operations execute according to a single total order (which is consistent with per-thread program order), all threads agree on this total order, and each read from a location reads the value of the most recent write to that location. Equivalently, SC is the model in which each memory operation takes full effect when it is performed and is immediately visible to all other threads.

\item Total store order (TSO) is a memory model in which all \emph{write} operations execute according to a single total order (which is consistent with per-thread program order). Each read operation may read any write that is not earlier in the store order than one that has already been read by that thread. Equivalently, TSO is the model in which each thread's writes are inserted into a buffer for that thread, and writes in the buffer may later propagate to other threads (but may not be reordered within the buffer).

\item Partial store order (PSO) is a memory model in which all write operations \emph{to the same location} execute according to a single total order (which is consistent with per-thread program order), but writes to different locations are unordered. Each read operation may read any write that is not earlier in its location's store order than one that has already been read by that thread. Equivalently, PSO is the model in which each thread has a write buffer for \emph{each location}, and writes in all buffers may later propagate to other threads (but may not be reordered within each buffer).
\end{itemize}

\section{Problems}
This is a written homework with 7 problems. For the first 6 problems, say whether the program running under the given memory model can produce the listed outcome, and explain why or why not. Assume that all memory locations are initialized to 0.

\newpage
\begin{enumerate}
\item 

Model: SC

Program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{store(y, 1)} \\
\texttt{r1 = load(y)} &\  \texttt{r2 = load(x)}
\end{tabular}

Result: \texttt{r1} = 1, \texttt{r2} = 0

\vspace{10em}

\item 

Model: SC

Program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{store(y, 1)} \\
\texttt{r1 = load(y)} &\  \texttt{r2 = load(x)}
\end{tabular}

Result: \texttt{r1} = 0, \texttt{r2} = 0

\vspace{10em}

\item 

Model: TSO

Program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{store(y, 1)} \\
\texttt{r1 = load(y)} &\  \texttt{r2 = load(x)}
\end{tabular}

Result: \texttt{r1} = 0, \texttt{r2} = 0

\vspace{10em}

\item 

Model: PSO

Program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{store(y, 1)} \\
\texttt{r1 = load(y)} &\  \texttt{r2 = load(x)}
\end{tabular}

Result: \texttt{r1} = 0, \texttt{r2} = 0

\vspace{10em}

\item 

Model: TSO

Program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{r1 = load(y)} \\
\texttt{store(y, 2)} &\  \texttt{r2 = load(x)}
\end{tabular}

Result: \texttt{r1} = 2, \texttt{r2} = 0

\vspace{10em}

\item

Model: PSO

Program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{r1 = load(y)} \\
\texttt{store(y, 2)} &\  \texttt{r2 = load(x)}
\end{tabular}

Result: \texttt{r1} = 2, \texttt{r2} = 0

\vspace{10em}

\item Explain why any outcome of a program that is possible under SC is also possible under TSO.

\end{enumerate}

\end{document}
