IT lexicon › Programming › Lock elision

Lock elision

Programming På svenska → Updated: 2026-11-06

The compiler or the processor skipping a lock it can prove, or bet, is never needed.

Java's old StringBuffer synchronizes every method, even when the buffer only ever lives inside one thread. HotSpot's C2 uses escape analysis to see that the object is never visible to another thread and removes the locking outright. A related pass, lock coarsening, merges several adjacent synchronized blocks on the same object into one, so the lock is taken once instead of ten times. Both work far better after inlining, because a call into unknown code always counts as an escape.

The name also covers Intel's hardware take, HLE, introduced with Haswell in 2013: the processor ran the critical section speculatively and only acquired the lock on conflict. A TSX bug got the feature switched off by microcode the following year, and it has since been phased out.

← Back to the lexicon