Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ECE478/CIS450/IMSE 450 Operating System Midterm test 2, July 2015 You have 1 hou

ID: 3919716 • Letter: E

Question

ECE478/CIS450/IMSE 450 Operating System Midterm test 2, July 2015 You have 1 hour and 45s to complete this test. State your answers clearly. 1.(20 points) a) Two concurrently running processes: PI with a statement S1 and P2 with a statement S2. Use the semaphore to synchronize both processes that make S1 executed only after S2 has completed. State the initial value of the semaphore. sets semaphert to Tahen b) What will happen when a process implements semaphore as signal...wait instead of So SI conm nos run, wait... signal? c) What will happen when a process implements semaphore as waits).. wait(s) instead of wait(s) signal (s)? isi orde 2. 130 points DOLL

Explanation / Answer

Semaphore

Semaphore is an interger variable 's' which is used to synchronize diffrent process to acess the critical section.

1)Binary Semaphores (Semaphore value is either 0 or 1)

2)Counting Semaphore (Semaphore value reange from -infinity to +infinity)

-----------------------------------------------------------------------------------------------------------------------------

Since in this problem we have only two process P1 and P2 access semaphore we can use the binary semaphore.

1)

Let us intialize the value os semaphore variable s as 0 and insert statements.

s=0;

//in process P2

S2; //Process P2 accessing critical section while s=0

signal(s); //signaling the process P1 that it can acess the critical section by making s=1

//--------------------------------------------------------------------------------

//in process P1

wait(s);// making value of s as 0 to enter into critical section

S1; // Accessing the critical section

//---------------------------------------------------------------------------------

2)

Generally the implementation of process synchronization would be like

do{

wait(s); // setting s=0

// critical section

signal(s); // setting s=1

// reminder section

}while(true);

By adding a wait(s) before entering to critical section ensure that the value of semaphore s is 0

that is the process which make s as 0 can only enter to the critical section (Implementation of mutual exclusion).

After the critical section the same process set s=1 which allows other process to enter into the critical section.

Now coming to our problem what happens if a process implements semaphore as signal....wait insted of wait...signal?

If we implement like this it will raise a problem.We are placing signal(s) before accessing the critical section the signal(s) wakeupa ll other process which were waiting for the critical section this will cause a problem that more than one process at same crtical section which is not allowed.

At the end there is another problem here we are placing wait(s) after acessing the critical section.By this implementation the other process which are wating for critical section won't know that the critical section is free which leads to a deadlock.

3)

What will happen when a process implements semaphore as wait(s)...wait(s) insted of wait(s)....signal(s)?

In this implementation only the first process trying to access critical section can only access the critical section because the after acessing the critical section the first process doses not signal others that critical section is free which lead to a deadlock.