CSE 330  Operating Systems Spring 2020
Assignment: #2
Due date: March 9 16 18

Note: You may choose to do this HW in groups of 2 or do it individually. Your choice, but if done in a group submit only 1 copy with two names.

1.     Suppose a system has an atomic hardware instruction SHIFT, that does the follows:

SHIFT ( int *A, *B ) { // both instructions executed ATOMICALLY, together
*B =*A;
 *A = 0;


A.    Implement Dijkstra style semaphores with the shift instruction, that is, semaphores which utilize busy waiting.

B.     Implement blocking semaphores using the shift instructions.

2.     // same as a sample exam question There are 4 processes, executing concurrently. Process P0 is in an infinite loop, incrementing the value of the variable x (x is initialized to 0). P0 is the only process that changes the value of x.
The rest of the processes Pi (1<= i <=3) monitor the value of x. Whenever x reaches a value such that it is divisible by i, Pi prints the value of x. For example, P3 will print the sequence 3 6 9 12 .. as the value of x reaches 3, 6, 9, 12 and so on.

Write the code for all the 4 processes using semaphores. Note that P1 - P3 should be identical; also Pi determines whether x is to be printed, and this decision is not made by P0.

Submission: Upload to canvas as one .doc or .pdf file. If you choose to handwrite, or use hand-drawn diagrams, take a picture of these material and embed them into the .doc or .pdf file. Make sure your name(s) are on the document.