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 P 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 P and P simultaneously execute TestAndSetLocklock instruction, what happens?
boolean Testandset boolean target
boolean target;
target TRUE;
return rv;
Figure The definition of the TestAndSet instruction.
do
while TestAndSetLock &lock
; do nothing
critical section
lock FALSE;
remainder section
while TRUE ;
Figure Mutualexclusion implementation with TestAndSet
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
