[concurrency-interest] Make the double-checked lock idiom broken on x86

Millies, Sebastian Sebastian.Millies at softwareag.com
Mon May 8 05:13:18 EDT 2017


You may find the following article by Aleksey Shipilev extremely helpful in understanding DCL (and related idioms)
http://shipilev.net/blog/2014/safe-public-construction
It has been sometimes mentioned on the list.

-- Sebastian

-----Original Message-----
From: Concurrency-interest [mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Yubin Ruan
Sent: Monday, May 08, 2017 4:22 PM
To: concurrency-interest at cs.oswego.edu
Subject: [concurrency-interest] Make the double-checked lock idiom broken on x86

Hi, from Bill Pugh's website[1] I read that the double-checked lock idiom is broken. Bill Pugh gave an example:

    // Broken multithreaded version
    // "Double-Checked Locking" idiom
    class Foo {
      private Helper helper = null;
      public Helper getHelper() {
        if (helper == null)
          synchronized(this) {
            if (helper == null)
              helper = new Helper();
        }
        return helper;
      }
      // other functions and members...
    }

His analysis is convincing, but the code he gave[2] work *well* on x86.
That is expected to break sometimes. But, running it from time to time, I never see it break.

How to verify that the double-check lock idiom will break on x86?

---
Yubin

[1]: https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
[2]: https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckTest.java
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Eric Duffaut, Dr. Wolfram Jost, Arnd Zinnhardt, Dr. Stefan Sigg; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com



More information about the Concurrency-interest mailing list