Published Sep 3, 2019

Episode 22: Feedback

Robert Blumen delves into listener feedback on model-driven development and software documentation, explores Java's Rife framework with continuations for enhanced flow management, and examines double-checked locking's interplay with the Java Memory Model, spotlighting `volatile` for thread safety.
Episode Highlights
Software Engineering Radio - the podcast for professional software developers logo

Popular Clips

Episode Highlights

  • Java Memory Model

    Double-checked locking in Java has often been misunderstood, but recent insights clarify its functionality under the current Java Memory Model. explains that the Java specification request JSR 133, finalized in 2004, introduced a new memory model that allows double-checked locking to work effectively with JDK 1.4 and JDK 1.5. This model ensures that only specific reorderings of instructions are allowed, providing a consistent view of variable states across threads 1.

    Double check clocking does work with current Java implementations, with the current Java virtual machine based on the new Java memory model.

    ---

    However, the problem is not unique to Java, as similar issues arise in other languages like C, which lack an explicit memory model 1.

       

    Reordering Challenges

    Instruction reordering is a common optimization in programming, but it poses challenges in multithreading environments. highlights that while reordering can optimize single-thread performance, it can lead to errors when multiple threads are involved 2. This is because a thread might access a partially initialized object due to reordering, causing unpredictable behavior.

    This is at the heart of why double check locking was broken.

    ---

    The introduction of the volatile keyword in Java addresses these issues by ensuring that write accesses to variables are immediately visible to all threads, reducing the risk of inconsistent views 2.

Related Episodes