intermediateMultithreading & Concurrency339 of 436
Why volatile doesn't make count++ atomic
Tests whether you know count++ is actually read-modify-write (three separate steps), and volatile only makes each individual read or write visible across threads -- it does nothing to stop two threads interleaving between those steps.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a responseNext Step
←PreviousContinue to What happens if a thread acquires a ReentrantLock and never calls unlock()? Why should unlock() sit in a finally block?→
← Back to all Core Java questions