← Lessons

quiz vs the machine

Silver1090

Concurrency

The Lock Striping Pattern

Spreading contention across a fixed array of locks instead of guarding everything with one.

4 min read · intro · beat Silver to climb

One lock per slice

Lock striping is the general technique behind a concurrent hash map. You allocate a fixed array of locks, called stripes, and map each piece of data to a stripe by hashing its identity. An operation locks only the stripe its data belongs to.

Why a fixed count

The stripe array stays a constant size even as the structure grows:

  • A table of millions of buckets might use only sixteen or sixty four stripes
  • Each stripe guards many buckets, but the mapping is stable, so a key always resolves to the same lock
  • A small fixed array keeps memory bounded and avoids creating a lock per element

The trade off

Striping reduces contention without eliminating it. Two unrelated keys can still collide on the same stripe and serialize, but the odds shrink as you add stripes. Operations that span multiple stripes, such as resizing or a global size count, must acquire locks in a consistent order to avoid deadlock.

Key idea

Lock striping maps data to a fixed array of locks, cutting contention while keeping lock memory bounded and the mapping stable.

Check yourself

Answer to earn rating on the learn ladder.

1. What does lock striping use to bound lock memory?

2. What risk appears when an operation spans multiple stripes?