Question: Iwo processes PO and P 1 are trying to enter their critical sections using the shared variable lock ( boolean ) and the TestandSetLock instruction.

Iwo processes PO and P1 are trying to enter their critical sections using the shared variable lock (boolean) and the TestandSetLock instruction. Initially, lock is set to FALSE.
(i) What is the purpose of TestAndSet() instruction?
(ii) Now, if both processes P0 and P1 simultaneously execute TestAndSetLock(lock) instruction, what happens?
boolean Testandset (boolean *target){
boolean rv=** target;
*target = TRUE;
return rv;
}
Figure 5.3 The definition of the TestAndSet () instruction.
do {
while (TestAndSetLock (&lock))
; // do nothing
// critical section
lock = FALSE;
// remainder section
}while (TRUE) ;
Figure 5.4 Mutual-exclusion implementation with TestAndSet ().
 Iwo processes PO and P1 are trying to enter their critical

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!