grayger
grayger

Reputation: 931

Application area of lock-striping

The ConcurrentHashMap of JDK uses a lock-striping technique. It is a nice idea to minimize locking overhead. Are there any other libraries or tools that take advantage of it? For example, does database engine use it?

If the technique is not so much useful in other areas, what is the limitation of it?

Upvotes: 1

Views: 2454

Answers (1)

Lock striping is useful when there is a way of breaking a high contention lock into multiple locks without compromising data integrity. If this is possible or not should take some thought and is not always the case. The data structure is also the contributing factor to the decision. So if we use a large array for implementing a hash table, using a single lock for the entire hash table for synchronizing it will lead to threads sequentially accessing the data structure. If this is the same location on the hash table then it is necessary but, what if they are accessing the two extremes of the table.

There is definitely a lot of time saved using lock striping. Multiple runs of a scenario gives almost halves the execution time.

The down side of lock striping is it is difficult to get the state of the data structure that is affected by striping. In the example the size of the table, or trying to list/enumerate the whole table may be cumbersome since we need to acquire all of the striped locks.

Upvotes: 4

Related Questions