HW 3
COMP 2004
Due Date: 30 Oct 2018
Tracing the behavior of two synchronized concurrent processes:
This hw is to be done strictly independently.
You have to write a program which does the following:
(A) Given a statement
$S \text{-} screate (p)$
where $screate$ is a keyword, $S$ is the name of the semaphore, and $p$ is an
integer constant used as the initial value of the semaphore $S$, it will set up
the semaphore $S$, initialing and setting up the associated waiting queue.
(B) Given a command
$wait(S)$
where $wait$ is a keyword, and $S$ is a semaphore, it will implement the seman-
tics of $wait$ (as explained in class).
(C) Given a command
$signal(S)$
where $signal$ is a keyword, and $S$ is a semaphore, it will implement the se-
mantics of $signal$ (as explained in class).
(D) Now, finally your program will trace the execution of any arbitrary,
but valid, sequence (see discussions in class) by two concurrent processes
synchronized by semaphores.
For the purpose of this assignment, consider a \text{``strip-down''} version of the
code used in the class, as follows:
\begin{itemize}
\item You do not need the declarations etc.
\item No need to spawn two processes, using $resume$ and $create$, $prod$ and
$cons$. We assume that the corresponding programs, $prod2$ and $cons2$
suffice.
\item The body of $prod2$ and $cons2$ contain only the labeled statements in-
volving $wait$ and $signal$.
\end{itemize}
1
Your program will be evaluated based on the usual metrics (see the
model software given in class)
Your output must display
\begin{itemize}
\item The value and the status of the semaphore queue;
\item the instructions being executed at each cycle;
\item and annotations explaining the event that arises in each cycle -
meaning why a particular command in the arbitrary sequence is
\text{``not valid''} and hence ignored.
\end{itemize}