



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The cs4410 prelim exam for a computer science course, focusing on java synchronization, thread performance, and paging. The exam includes three problems: java synchronization for sharing windows display handles among threads, improving the performance of a web server application using multithreading, and understanding the impact of paging on cpu performance. Students are expected to write java code for the first problem and provide explanations for the other two.
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




This exam has four questions for a total of 100 points In class, closed book, 75 minutes….
Problem 1: Java synchronization. 20 points
An application containing 25 threads in a single process uses windows display handles to talk to the display. The application has a set of 3 handles available and they must be shared among the threads. Assume that a windows display handle is of type WDH. Code a Java class called DispHandles with the interface shown below, using the Java synchronization mechanism that seems most appropriate to you:
A thread may call int Thread.currentThread().getId() to get a unique positive ID.
Class DispHandles { WDH[] Handles = new WDH[3]; int[] InUse = new int[3]; Semaphore mutex = 1, count = 3;
// Constructor notes the Handles pointers and // marks each as available (InUse[k] = ‐1) Public DispHandles(WDH h0, WDH h1, WDH h2) { Handles[0] = h0; Handles[1] = h1; Handles[2] = h2; InUse[0] = InUse[1] = InUse[2] = ‐1; }
// Grab uses a counting semaphore to make sure one is available // If so, get Mutex and find a free handle, mark it as in use “by me” Public WDH Grab() { count.acquire(); mutex.acquire(); for(int k = 0; k < 3; k++) if(InUse[k] == ‐1) break; InUse[k] = Thread.currentThread().getId() ;
mutex.release(); Return Handles[k]; }
// Release figures out which handle the caller is using and frees it // then releases the semaphore. Needs Mutex to protect against // concurrent calls to Grab or Release Public void Release() { mutex.acquire(); for(int k = 0; k < 3; k++) if(InUse[k] == T hread.currentThread().getId() ) break; InUse[k] = ‐1; mutex.release(); count.release(); } }
Problem 2: Programming with Threads. 10 points.
You have been hired by Amazon.com to improve the performance of a web server application that runs on a single‐core machine rated at 2GHz. You measure its performance; the server needs 100 seconds to construct and transmit 1000 web pages in response to requests from 10 client browsers. Having received an A in Cornell’s CS4410, you are a world expert on multi‐threading code, and the application appeared to have a lot of potential to benefit from threading. Accordingly, you modify the application into a multi‐threaded version and run it with four threads on the same machine. Unfortunately, now it takes 150 seconds to do the exact same workload! Assume that the multithreaded code is correct and thread safe, and that nothing else is running on the machine. What could cause this multi‐threaded, single‐core, slowdown? We’re looking for a single “main” reason described in a short answer.
The most likely explanation is that the cost of context switching is high. Thread context switching is usually quite cheap, but if the threads use an inefficient synchronization mechanism that involves a lot of contention (e.g. for locks), they can spend a ton of time context switching from thread to thread without much work actually being done.
We will also give full credit for answers that argue that the threads are causing contention within the processor (L2) memory cache or that context switching is preventing the processor from achieving the normal level of pipelining (for example by causing branch prediction to fail). However, we’re skeptical that this would be the most likely cause of the slowdown.
Problem 3: Paging. 40 points
For a‐b: Suppose that you are working on an operating system that implemented a paged page table, meaning that the memory used to store a page table is itself virtual and might be paged in and out. Assume that the size of a page table entry is 32 bytes.
Completely false. The clocked version of the working set algorithm runs on the actual page reference sequence, which it detects in a simple way by periodically marking all pages as idle, and then remarking them as “in use” one by one as pages are touched. No prediction of future behavior is needed.
g) [5 points]. True or false (explain briefly): The Working Set Algorithm (WS) and the Optimal Working Set policy (WSOPT) achieve the same page hit rate.
True. We proved this in class. Basically, at each time step t, the WS algorithm pages out the page referenced at time t ‐ Δ if that page wasn’t touched in the period t ‐ Δ+1 through t. WSOPT made exactly the same decision, except that it paged the same page out Δ time units earlier.
h) [5 points]. True or false (explain briefly): The Working Set Algorithm (WS) and the Optimal Working Set policy (WSOPT) maintain the identical set of resident pages at all times after t=Δ.
False: WS will keep pages around for Δ time units longer than WSOPT, so in general it has extra pages beyond the actual working set.
Problem 4: Internet. 30 points.
a) [10 points] Is it possible for two computers on the Internet to simultaneously have the same IP address? Explain why not, or (if it is possible), give examples of situations where this can happen.
Definitely. For example, two people might both own LinkSys wireless routers. The routers will have different external IP addresses, but within the two wireless regions, each router might use the same IP addresses. Thus there could be two machines that both have IP address 192.168.1.10 – perhaps one in your friend’s house and one in your house.
b) [10 points] You measure the performance of a TCP connection between two computers in your network and end up with the following graph showing the bandwidth the sender is sending at (bytes/second), the speed of the network itself (“max bandwidth”) and, on the x‐axis, elapsed time. Explain why the graph has this strange shape. Notice that we’ve labeled parts of the graph. We’re hoping that you’ll use these labels in your brief written explanation to help us connect your answer to the picture in a standard way. Of course you may not need to mention every single label: to be on the safe side, we included plenty of them, in the hope that no matter what your answer is, you could still use these labels to organize it in a clear way.
(a) is showing “slow start”: TCP starts up by repeatedly doubling the speed of transmission until it experiences a packet loss (b), which occurs when it exceeds the actual maximum speed of the network. At that point it uses a “multiplicative” slowdown (here it seems to halve the speed: event (c)). Now we enter a mode in which TCP ramps up (“additive” speedup”), then goes over the maximum and experiences a loss, then does a multiplicative slowdown, again and again (shown as (d), (e), etc).
c) [10 poi the Intern intruder s your two
The Intern chunks th peek into communic is basicall
nts] Suppose net and then somewhere i computers (t
net isn’t very hat fit into IP o the packets cation too. F ly a radio broa
e that you wri n sends credi n the Interne the sender an
secure at all, packets. Thu s and see the For example, adcast and an
ite a program it card inform et might man nd the receive
, and TCP doe us, an intrude eir contents. if the commu nyone with a
(a)
m that makes mation over t nage to obta er)? Explain v
esn’t normally er who sits on There are unication pas n antenna ca
(b)
(c) (
a TCP connec the TCP conn in a copy of very briefly.
y encrypt or h n a router be other ways t sses over a w an see the pac
d)
ction to a rem nection. Is i the list, with
hide data – it tween your t the intruder ireless netwo ckets.
(e)
mote location t possible th hout breaking
t just breaks i wo sites coul might spy o ork, every me
n over hat an g into
it into ld just on the ssage