\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 2026\\ Due Sep. 4}
\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 that is consistent with per-thread program order, and each memory operation takes full effect when it is performed (so it is immediately visible to all other threads).

\item Total store order (TSO) is a memory model in which store operations take effect in the order they are performed within each thread, but may take time to complete---a store in one thread may not propagate to other threads until later, but all stores from a thread propagate in the order they were performed. Equivalently, TSO is a memory model in which stores may be moved down in a thread past past loads to other locations.

\item Partial store order (PSO) is a memory model in which store operations \emph{to each location} take effect in the order they are performed within each thread, but stores to different locations may not propagate in the order they were performed. Equivalently, PSO is a memory model in which stores may be moved down in a thread past past loads and stores to other locations.
\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}

Outcome: \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}

Outcome: \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}

Outcome: \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}

Outcome: \texttt{r1} = 2, \texttt{r2} = 0

\vspace{10em}

\item

Model: PSO

Program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{r1 = load(x)} \\
\texttt{store(y, 2)} &\  \texttt{r2 = load(y)}\\
\texttt{store(x, 3)} &\\
\end{tabular}

Outcome: \texttt{r1} = 3, \texttt{r2} = 0

\vspace{10em}

\item

Model: TSO

Program:

\begin{tabular}{l || l || l || l}
\texttt{store(x, 1)} &\ \texttt{store(y, 2)} &\ \texttt{r1 = load(x)} &\ \texttt{r3 = load(y)} \\
 & &\ \texttt{r2 = load(y)} &\ \texttt{r4 = load(x)}
\end{tabular}

Outcome: \texttt{r1} = 1, \texttt{r2} = 0, \texttt{r3} = 2, \texttt{r4} = 0\\
(This is a tricky one. You may want to work through a few definitely-possible outcomes first.)

\vspace{10em}

\item Explain why any outcome of a program that is possible under SC is also possible under TSO.

\end{enumerate}

\end{document}
