\documentclass{article}

%\setlength{\oddsidemargin}{0.0 in}
%\setlength{\evensidemargin}{0.0 in}
%\setlength{\textwidth}{7.0 in}

\oddsidemargin 0cm
\topmargin -2.5cm     
\textwidth 16.5cm   
\textheight 24.0cm 

\def\titledquestion#1#2{\section{ {#1} ({#2} pts.)}}
\begin{document}
\begin{center}{\large 15-410, Fall 2005, Homework Assignment 1.} \\
\Large{Due Monday, October 10, 6:59:59 p.m.}
\end{center}

%{\small Please} observe the {\large non-standard} {\Large submission time}...
{\Large Please} {\large observe the} non-standard {\small submission time}...
As we intend to make solutions available on the web site immediately
thereafter for exam-study purposes, please turn your solutions
in on time.

Homework must be submitted in either PostScript or PDF format (not:
Microsoft Word, Word Perfect, Apple Works, LaTeX, XyWriter, WordStar,
etc.).  Submit your answers by placing them in the appropriate
hand-in directory, e.g.,
{\tt /afs/cs.cmu.edu/academic/class/15410-f05-users/\$USER/hw1/\$USER.ps}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \newpage
\titledquestion{Run Away}{10}

Consider the following ``flee'' facility, essentially a
simplified version of {\tt setjmp()}/{\tt longjmp()} with
more-suggestive names.

\begin{verbatim}
#include <unistd.h>
#include <flee.h>

flight_path all_the_way_home;

void main(void)
{
  char *relief;

  if (we_fled(&all_the_way_home)) {
    fprintf(stderr, "Run away!!!\n");
    exit(2);
  }

  relief = "Whew!";
  is_it_safe();
  printf("%s\n", relief);

  exit(0);
}

void is_it_safe(void)
{
  if (access("/dangerous", F_OK) == 0)
    flee(&all_the_way_home);
}
\end{verbatim}

\subsection{5pts}
Explain roughly how {\tt flee()} works.

\subsection{5pts}
What are the fields of a {\tt flight\_path}?  Be specific if you can.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\titledquestion{Racy}{15}

Consider the following critical-section entry protocol.

\begin{verbatim}

       boolean critical[2] = { false, false };

 1.    do {
 2.       ...think great thoughts...
 3.       while (critical[j])
 4.          continue;
 5.       critical[i] = 1;
 6.       ...begin critical section...
 7.       ...end critical section...
 8.       critical[i] = 0;
 9.    } while (1);

\end{verbatim}

(This protocol is presented in ``standard form,'' i.e.,
if process 0 is running this code, $i == 0$ and $j == 1$;
if process 1 is running this code, $i == 1$ and $j == 0$.)

For each critical-section protocol property, argue briefly but
convincingly whether this protocol does or does not fulfill the
property.  You may wish to use the tabular process execution
trace format found in the lecture slides.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\titledquestion{Fascinating}{10}

Consider a system with three processes and three tape drives.
The maximal needs of each process are declared below:

\begin{tabular}[b]{|l|c|l|c|l|}
\multicolumn{5}{c}{Resource Declarations} \\
\cline{1-1} \cline{3-3} \cline{5-5}
Process A && Process B && Process C \\
\cline{1-1} \cline{3-3} \cline{5-5}
2 tape drives && 2 tape drives && 2 tape drives \\
\cline{1-1} \cline{3-3} \cline{5-5}
\end{tabular}

\subsection{4 pts}  Is the following state safe?  Why or why not?

\begin{tabular}[b]{|l|r|r|r|}
\multicolumn{1}{c}{Who} &
 \multicolumn{1}{c}{Max} &
 \multicolumn{1}{c}{Has} &
 \multicolumn{1}{c}{Room} \\
\hline
A      & 2 & 1 & 1 \\ \hline
B      & 2 & 1 & 1 \\ \hline
C      & 2 & 0 & 2 \\ \hline
System & 3 & 1 & - \\ \hline
\end{tabular}

\subsection{4 pts}  Is the following state safe?  Why or why not?

\begin{tabular}[b]{|l|r|r|r|}
\multicolumn{1}{c}{Who} &
 \multicolumn{1}{c}{Max} &
 \multicolumn{1}{c}{Has} &
 \multicolumn{1}{c}{Room} \\
\hline
A      & 2 & 1 & 1 \\ \hline
B      & 2 & 1 & 1 \\ \hline
C      & 2 & 1 & 1 \\ \hline
System & 3 & 0 & - \\ \hline
\end{tabular}

\subsection{2 pts}  Is there something odd about this system?

\end{document}
