in Operating System
970 views
1 vote
1 vote

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

in Operating System
970 views

1 Answer

0 votes
0 votes

The above code prevents deadlock. The detailed explanation is provided in pictures below:

 

4 Comments

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
0

@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
0
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
0

Related questions