\documentclass[11pt]{article}

\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{a4paper}

\usepackage{verbatim}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{mathpartir}
\usepackage{semantic}

\title{HW4 -- Language Memory Models}
\author{CS 554, Fall 2026\\ Due October 30}
\date{}

\begin{document}
\maketitle

\section{Problems}
This is a written homework with 3 problems, each of which has multiple parts. See \url{https://www.cs.uic.edu/~mansky/teaching/cs554/fa26/lectures/language-models.pdf} for the definitions of the memory models.

\begin{enumerate}
\item Consider the following C program:

\begin{tabular}{l || l}
\texttt{acquire(a);} & \ \texttt{acquire(b);} \\
\texttt{*x = 5;} & \  \texttt{y = *x;} \\
\texttt{release(b);} & \texttt{release(a);}
\end{tabular}

\begin{enumerate}
\item Intuitively, do you think this program has a data race? Why or why not?

\vspace{10em}

\item Draw an execution graph for the program under the SC-DRF model. Indicate whether it has a data race according to the model's rules.

\vspace{12em}

\end{enumerate}

\newpage
\item Consider the following C program:

\begin{tabular}{l || l}
\texttt{*y = 1;} & \ \texttt{while(atomic\_load(x) != 1) \{\ \}} \\
\texttt{atomic\_store(x, 1);} & \  \texttt{b = *y;} \\
\texttt{*y = 2;} &
\end{tabular}

\begin{enumerate}
\item Draw an execution of this program under RA+NA that has a data race. Be sure to indicate which two operations race with each other. You may check your answer using CppMem.

\vspace{16em}

\item How could we change the program to remove this data race?

\end{enumerate}

\newpage
\item For each of the following programs, draw a RA+RLX+NA execution graph for the outcome where \texttt{a} is 5, and indicate whether it has a data race.
\item \begin{tabular}{l || l}
\texttt{*x = 5;} & \ \texttt{while(atomic\_load(y, ra) != 1) \{\ \}} \\
\texttt{atomic\_store(y, 1, ra);} & \  \texttt{a = *x;}
\end{tabular}

\vspace{13em}

\begin{enumerate}
\item \begin{tabular}{l || l}
\texttt{*x = 5;} & \ \texttt{while(*y != 1) \{\ \}} \\
\texttt{*y = 1;} & \  \texttt{a = *x;}
\end{tabular}

\vspace{13em}

\item \begin{tabular}{l || l}
\texttt{*x = 5;} & \ \texttt{while(atomic\_load(y, rlx) != 1) \{\ \}} \\
\texttt{atomic\_store(y, 1, rlx);} & \  \texttt{a = *x;}
\end{tabular}

\vspace{12em}
\end{enumerate}

\end{enumerate}

\end{document}
