CS414 Prelim 2.
5 questions
1.
T-Bone’s
Mutt Home
When a dog wants to go
outside
Some dogs are mean. There is a table nice[0..D-1] such that nice[i] is
true if dog i can play with others. If a dog isn’t
nice
We’ll model dogs as processes. Write a monitor with entry points IWantToGoOut(d) and BackInside(d) implementing the door
latch.
Monitor kennel
{
Boolean nice[0..D-1] = { ….. }; /* Assume this is initialized
appropriately */
Condition
Mean
Int Ncnt = 0
Void IWantToGoOut(int id)
{
if(nice[id] == false)
MeanDogGoesOut();
else
NiceDogGoesOut();
/* INCLUDED JUST FOR CLARITY */
UnlatchTheDoor(id);
If((NCnt+Mcnt) == 1)
StartTheTimer();
}
Void BackInside(int id)
{
/* ALSO INCLUDED FOR CLARITY */
LatchTheDoor(id);
if(nice[id] == false)
MeanDogCameIn();
else
NiceDogCameIn();
}
/* The remainder is just readers and
writers
void NiceDogGoesOut()
{
if(Mcnt > 0)
{
++Nwait; Nice.wait(); --Nwait;
}
++Ncnt;
Nice.signal();
}
void MeanDogGoesOut()
{
if(Ncnt > 0 ||
Mcnt > 0)
Mean.wait();
Mcnt = 1;
}
void NiceDogComesIn()
{
if(--Ncnt ==
0)
Mean.signal();
}
void MeanDogComesIn()
{
Mcnt = 0;
If(Nwait >
0)
Nice.signal();
else
Mean.signal();
}
}
2.
In class we
learned how the TCP protocol works.
a. Suppose that
machine A is connected to machine B by a wireless link that runs at 10MB/sec but
drop messages now and then. The
communications link is idle.
Now
As we saw on one
of the homework problems
b. Suppose that
a machine is sending variable-length records over a TCP connection. For example
TCP doesn’t
include any indication of record lengths.
So you need to send this information as part of the record. That way the remote machine can read the
length
c. TCP
increases its sending rate linearly (by adding steadily to the
rate)
TCP does this
because there is a time lag between when the network gets overloaded and when it
detects the problem. When it
increases its sending rate
3.
A
bird-watching computer network has five cameras controlled by programs
P0 … P4 (running on machines M0 …
M4) and a sixth server computer running a file server program
FS. When a camera spots a
bird
a. Would it be
easier (require less code on your part) to use UDP or
TCP to send the picture files from the camera programs to the DB
system?
TCP makes more
sense. Why reinvent the wheel? If you use UDP
b. Suppose the
cameras have very well synchronized clocks and that the pictures include the
time when they were taken. Is it
possible that the pictures in the DB file might end up “out of
order”
Yes
c. We don’t
want to print the “birds of the day” file until we are sure that all the
pictures are safely written to it.
What would you do to ensure that the DB program knows when it has all the
pictures? Assume that nothing
crashes.
At the end of the
day
4.
A CNN web
page lists some URLs on archive.cnn.akamai.com. You run ping from home (road runner) and
then at Cornell (campus network).
a. From home
“ping cnn.com” takes 55ms. From Cornell it takes 123ms. They list identical IP addresses
for cnn.com. List some possible reasons for the round-trip time
difference.
The CNN web site
may be reached by very different routes even from machines that are physically
near one-another
b. Now you ping
archive.cnn.akamai.com. Both report
18ms
Akamai uses the DNS to
map the SAME computer name into DIFFERENT IP addresses corresponding to
different servers within its data centers (and it has many of them). So
c. You set up
your home computer to host a file sharing program and give out your IP
address. But nobody is able to
connect. Explain why this might happen.
Many network
providers use firewalls and/or network address translation. This can mean that your IP address as
seen “in the network” won’t be the same as it is when seen “from at home”. Either of these can cause the problem –
either your external IP address isn’t what you think it
is
5.
Below is are
two memory reference tableaus for the same reference string. We assume a
fixed sized memory partition of size D =
4 pages.
a. Fill in the
two tables
LRU
R(t) |
9 |
7 |
1 |
3 |
9 |
5 |
6 |
1 |
2 |
9 |
7 |
8 |
1 |
2 |
1 |
3 |
1 |
4 |
9 |
7 |
1 |
3 |
9 |
1 |
3 |
S0 |
9 |
7 |
1 |
3 |
9 |
5 |
6 |
1 |
2 |
9 |
7 |
8 |
1 |
2 |
1 |
3 |
1 |
4 |
9 |
7 |
1 |
3 |
9 |
1 |
3 |
S1 |
Æ |
9 |
7 |
1 |
3 |
9
|
5 |
6 |
1 |
2 |
9 |
7 |
8 |
1 |
2 |
1 |
3 |
1 |
4 |
9 |
7 |
1 |
3 |
9 |
1 |
S2 |
Æ |
Æ |
9 |
7 |
1 |
3 |
9 |
5 |
6 |
1 |
2 |
9 |
7 |
8 |
8 |
2 |
2 |
3 |
1 |
4 |
9 |
7 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
Æ |
Æ |
Æ |
7 |
1 |
3 |
5 |
Æ |
6 |
1 |
2 |
7 |
Æ |
8 |
Æ |
2 |
Æ |
3 |
Æ |
4 |
Æ |
Æ |
Æ |
b. Now compute
the hit ratios for the time period t=5…25 (the part you filled
in)
HitRatio(LRU) = 7/21 (.333)
HitRatio(LFU) = 9/21 (.429)
c. Suppose that
when using this sort of table
No. When we make these
tables