Question: A spin lock acquire ( ) can be implemented with a test - and - set instruction as follows: while ( test - and -

A spin lock acquire() can be implemented with a test-and-set instruction as follows:
while (test-and-set(&lock->held)==1)
; // spin
Recall that test-and-set()returns the old value at the address while atomically setting it to 1. Now a
new lock acquire() is implemented as follows:
1: while (1){
2: while (lock->held >0)
3: ; // spin
4: if (test-and-set(&lock->held)==0)
5: return;
6: }
i). Does it work? Ho

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!