Previous | Next --- Slide 27 of 35
Back to Lecture Thumbnails
bpr

Question: It was posed in class, how many cache lines are accessed by a thread through the Acquire and Release routines? What is the worse case number of coherence requests?

MangoSister

I am a little confused about the "if(mlock->next == NULL)" block of ReleaseQLock function. Why do we still need to use CMPXCHG to set glock to NULL since there should be only one thread holding the last element of the queue (mlock->next == NULL). Also, why do we need to check if x == mlock before return as it should always be true? Am I missing something?

bpr

@MangoSister, at the time of the check, the releasing thread is the only one "in the queue", but at that same time, another thread may be about to execute prev->next = mlock; in the acquire path. The entire if clause is for handling this "race".

autumnust

Can someone help on this slide? Don't quite get the idea here. Also, why it is designed in this way, with glock and mlock? Thx.

bpr

@autumnust, I would suggest that you either work through the associated exercises for this lecture (see the lecture tab). Or you can visit my office between 2-4pm today.

autumnust

Thanks. @bpr

FYI, I got a good explanation for this from Quora. There are minor terminology mistakes(from our convention) in his post but overall, it is clear and easy to understanding.

https://www.quora.com/How-does-an-MCS-lock-work