operating system

profileopi1206
O.SASSIGNMENT.pdf

Prof. Pitts CS554AH1: Operating Systems Spring 2018

Assignment 3

This is an individual assignment; the work you submit should be your own work and not that of any other person. Be sure to cite the sources for any information you use to answer the questions below. Do not copy and paste your answers as you

will lose marks; use your own words to rephrase the information you use from other sources. Label each answer in your submission with the number of the homework question it belongs to. Do not copy the questions to your PDF document.

Submit your answers in a PDF document through Canvas.

1. Let mySem be a semaphore and let P1, P2, P3 be three processes that use the semaphore. For each of the three

sequences of semaphore calls (acquire() to take the semaphore, release() to give up the semaphore), provide the following information for each call

▪ for acquire() calls show the new value of count and indicate whether the calling process blocks on the

semaphore or proceeds to its critical section

▪ for release() calls show the new value of count and indicate whether a process is removed from the

semaphore blocked queue (and if so which one)

▪ show the semaphore queue for each call

Assume the processes make the semaphore calls in the order given and that the semaphore count is initialized as specified.

Initial semaphore count is 1 Initial semaphore count is 2 Initial semaphore count is 0

P1: acquire() P1: acquire() P1: acquire()

P2: acquire() P2: acquire() P2: acquire()

P3: acquire() P3: acquire() P3: release()

P1: release() P1: release() P2: release()

P1: acquire() P1: acquire() P1: release()

P2: release() P2: release() P3: acquire()

P3: release() P3: release() P2: acquire()

2. Let mutexOne and mutexTwo be a binary semaphores (count is initially 1). Consider the partial code sequences for two processes P1 and P2. Assume that mutexOne and mutexTwo are free (their counts are still 1), when the

code below is executed and that the order given below is the order in which the semaphore calls occurs. What happens?

P1: mutexOne.aacquire()

P2: mutexTwo.acquire()

P2: mutexOne.acquire()

P1: mutexTwo.acquire()

1/2

Prof. Pitts CS554AH1: Operating Systems Spring 2018

3. Consider the code for three processes shown below. The code attempts to ensure that only one process at a time is in critical sections A and B using the semaphore mutex. What is the problem with code?

Process 1 { . . .

mutex.acquire()

//Critical section A

mutex.release() . . .

}

Process 2 { . . .

mutex.acquire()

//Critical section B

mutex.release() . . .

}

Process 3 { . . .

mutex.release()

mutex.acquire() . . .

}

2/2