Previous | Next --- Slide 26 of 35
Back to Lecture Thumbnails
anamdev

I'm a little confused on Array-based locks. Are we saying that the entire array is locked if a processor is accessing it, or the specific address in the array is locked?

acortes

What does the head represent here? Head doesn't seem to be modified anywhere but status[head ++] seems to define our element's status.

kamikaze

The head is an arbitrary int for indexing the lock array that's incremented circularly such that there's never an out of bounds access on said array. Another reason for being circular is to limit the number of locks available for use (presumably based on the size of the cache).

cuiwei

Is it possible that, there are a large number of requests for a lock such that 2 different threads ends up with the same value for 'my_element' variable, and then both of them enters the critical section?

cuiwei

Also, what are the values initially stored in the status array? I assume that status[head] would be 0 and all the rest are 1.

bpr

@cuiwei, there are P elements of status, one per processor. Note that each status is a "padded int", to be on separate cache lines. As for the values, one status is 0 and the rest are 1. Recall though that head indicates where the next waiter should be in the queue, not which one is currently holding the lock (i.e., the value of 0).