Previous | Next --- Slide 21 of 35
Back to Lecture Thumbnails
gogogo

Locks have been mentioned repeatedly to be fairly expensive; are they expensive primarily because of the while(1) spinning part?

bpr

@gogogo, there are three components to lock performance: acquire, wait, release. Even if this lock is acquired without spinning, the atomic test_and_set will still act as a full memory barrier and cost tens of cycles. Beyond that, much of this lecture is about finding the right trade-off in these three components of the synchronization implementation. For instance, this test-and-test-and-set lock is more expensive to acquire under zero contention, but cheaper under high contention.