Previous | Next --- Slide 54 of 90
Back to Lecture Thumbnails
pslui88

In class, Kunle noted that the 4 lines starting at the lock label look like a spin lock because they repeat until the condition is false. However, it is not a spin lock at all because it is not locking at all! It is definitely spinning, but because there is no mechanism protecting its load and test, another processor can interleave a write 0, and the original processor would not know. Thus, the next slide introduces an atomic test-and-set instruction that removes the chance for another processor to intercept the test and set and cause problems.

Nian

mem[addr] stores the value of the lock?

nickbowman

@Nian addr is the address of the lock and mem[addr] stores the value of whether or not the lock is currently locked or not (1 means that the lock is held by a thread, 0 means the lock is held by nobody)

Please log in to leave a comment.