COMP 346 Winter 2000: TA-2

Task Deadline
Computer Structure, OS Structure Thursday, Feb. 17, 2000
Answer the following questions. The maximum number of points for this assignment is 125. The points for each individual question are indicated below.
  1. Assume that we have a computer with 7 identical CPUs. Show how we can run a given process P on this machine if the process consists of the following piece of code. For each case, indicate how many threads there are in the process. Describe those threads!
    1. [Points: 5]
    2. 	for ( i = 1 ; i <= 100 ; i++ )
      		X[i] = X[i] + S ;		// X is an array and S is a 
      						// scalar 
      
    3. [Points: 5]
    4. for ( i = 1 ; i <= 100 ; i++ )
      		Y[i] = Y[i] + Y[i+1];	// Y is an array
      
    5. [Points: 15]
    6. for ( i = 1 ; i <= 100 ; i++ ) {	// Hint: You can make this 
      						// loop parallel
      		A[i]	= A[i] + B[i];
      		B[i+1]	= C[i] + D[i]; 	// A, B, C and D are arrays
      	    }
      
      

  2. Answer Question 6.3 in the textbook (Silberschatz & Galvin, 5th ed.) [Points: 20]

  3. Answer Question 6.6 in the textbook (Silberschatz & Galvin, 5th ed.) [Points: 15]

  4. Answer Question 7.13 in the textbook (Silberschatz & Galvin, 5th ed.) [Points: 25]

  5. Consider the following situation with the synchronization of two processes.
  6.             ---------------------------------------------------------------
                Process A            			    Process B
                ---------------------------------------------------------------
                while True do         		while True do
                   na = na + 1 ;       		    nb = nb + 1 
                end                      		end
    

    1. Synchronize the execution of the two processes using two general semaphores such that at any time nb < na <= nb + 10. Assume that initially na = nb = 0. [Points: 5]
    2. How would you modify (simplify) your solution if the only constraint is na <= nb + 10? [Points: 5]
    3. Would your solutions for (1) and (2) be still valid if there are several A and B type processes executing the same code? If your answer is YES, explain why; if it is NO give the correct solutions. [Points: 15]
  7. A variable X is shared by two processes executing the following program fragment:
                repeat
                X := X + 1  ; 
                if (X = 20) then X := 0 ; 
                forever; 
    
    Starting from an initial value of 0, show that it is possible for the value of X to increase beyond 20. What can you do to ensure that the value of X does not go beyond 20? [Points: 15]


Franz Kurfess
Last modified: Fri Feb 4 10:23:14 EST 2000