HardExperience level: 8-15 years1 min read

What is false sharing, and how does it silently kill multi-threaded throughput?

Reviewed by Gurusankar M.

Asked inGoogleAmazonMicrosoft
#false sharing#cache line#contended#performance#cpu cache
Report issue

Short Answer

CPUs move memory in ~64-byte cache lines. If two threads update different variables that sit on the SAME line, each write invalidates the other's cached line — so independent variables ping-pong between cores. Fix with padding or @Contended.

On this page

Concept Made Simple

Coffee Chat Question

“What is false sharing, and how does it silently kill multi-threaded throughput?”

Remember It Faster

Mind Map Answer

Cache line
~64 bytes moved as a unit
Problem
2 hot vars share one line → invalidation
Fix
padding / @jdk.internal.vm.annotation.Contended

Think Beyond the Expected

What If?

How does LongAdder relate to false sharing?

LongAdder spreads counts across multiple Cell objects, and those cells are @Contended-padded so each sits on its own cache line. That avoids both CAS contention AND false sharing — which is why it scales far better than a single AtomicLong.

Real World

False sharing is an invisible scalability killer in hot concurrent counters and ring buffers; high-performance libraries (LMAX Disruptor, JDK LongAdder) pad fields to cache-line boundaries specifically to avoid it.

Interviewer's Expectation

Keywords they're listening for:

  • cache line ~64B
  • independent vars same line → invalidation
  • padding / @Contended
  • LongAdder/Disruptor examples

Common Mistakes

  • Packing hot per-thread counters into one object
  • Assuming independent fields can't contend
  • Optimizing without measuring cache effects

Best Practices

  • Use LongAdder for hot counters (padded for you)
  • Pad/@Contended only proven-hot fields
  • Profile with perf / async-profiler before padding

Follow-up Questions

  1. How do you measure/confirm false sharing?
  2. How does the LMAX Disruptor avoid it?
  3. Why is @Contended internal/guarded by a flag?

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Atomics (Multithreading)
Interview question: "What is false sharing, and how does it silently kill multi-threaded throughput?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.