

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CIS6930 Concurrent Programming Assigned: 8/30/ Due: 9/6/
Read the command line arguments N, D, and S Create and start N threads Record the current time Enter the following loop do{ sleeps for S msecs [ prints the value of x while{ D seconds have not elapsed } Print a list of the names of the threads that are still alive Interrupt remaining alive threads Terminate
while(!interrupted()) { t = x; x = x+inc; assert t+inc==x : thread name; }
[Hints: You will need the following methods: java.lang.System.currentTimeMillis; and from java.lang.Thread: sleep, activeCount, isAlive, enumerate, interrupt, interrupted. The code fragments above are only to indicate what needs to be done. You will need to correct some details. Also, you should NOT use any kind of synchronization for this assignment.]
class hw1_ { int r,w;
public hw1_2(){_______________}
void m() { if ___________________ r := r+1; else if __________________w := w + 1; else ; //skip }
}
Suppose that the invariant of this class is (0 ≤ w ≤ 1) ∧ (r = 0 ∨ w = 0)
a. Describe the values of r and w that satisfy the invariant. b. Provide a body for the constructor that explicitly establishes the invariant. c. Fill in the guards of the if statement so that the invariant is preserved. Use the weakest guards possible.