Hard👤 8-15 years 1 min read

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

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.

Coffee Chat Question

Concept Made Simple

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

🧠Mind Map Answer

Remember It Faster

Cache line~64 bytes moved as a unit
Problem2 hot vars share one line → invalidation
Fixpadding / @jdk.internal.vm.annotation.Contended

🔥What If?

Think Beyond the Expected

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 ~64Bindependent vars same line → invalidationpadding / @ContendedLongAdder/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

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

🧩Related Technologies

LongAdder@ContendedLMAX Disruptorasync-profiler

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?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions