1 votes 1 votes There are two threads which try to solve critical section problem using Test-And-Set instruction. Does the above code prevent deadlock? please provide reason to your answer Operating System operating-system process-synchronization critical-section deadlock-prevention-avoidance-detection test-and-set-instruction + – Tuhin Dutta asked Oct 8, 2017 Tuhin Dutta 984 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes The above code prevents deadlock. The detailed explanation is provided in pictures below: SuvasishDutta answered Jul 1, 2019 SuvasishDutta comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments SuvasishDutta commented Jul 3, 2019 reply Follow Share Absolutely right @srestha mam. T2 will busy wait i.e. it will be in a spinlock since blocking of processes, if they have to wait to enter C.S. ,is not mentioned in the code. 0 votes 0 votes srestha commented Nov 5, 2019 reply Follow Share @SuvasishDutta In your point , u mentioned p1MustWait will be False. But in code nowhere it is mentioned as false. Then how are u getting it false? 0 votes 0 votes SuvasishDutta commented Nov 6, 2019 reply Follow Share If thread1 enters the while loop and executes the testandset instruction first, then p1mustwait will be assigned the value of occupied and occupied is assigned false initially. I had mentioned it in the picture. 0 votes 0 votes Please log in or register to add a comment.