Previous | Next --- Slide 66 of 70
Back to Lecture Thumbnails
zvonryan

Using finer-granularity locks might result in significant performance decrease.

CaptainBlueBear

In this case, we get a performance increase from using a finer-granularity lock. Instead of locking the whole array whenever a thread tries to update the count for a certain cell, we're now locking only the specific cell index we're locking. This means there's less contention between the threads (which means increased performance); instead of every thread waiting on a lock to update cell count, only threads that are updating the same cell are waiting on each other.