Skip to content

双重检查加锁单例模式 是否需要加 volatile 关键字修饰? #5

Open

Description

@SummerXSH

在双重检查加锁单例模式 是否需要加 volatile 关键字修饰来保证可见性问题?

Activity

  1. youlookwhat commented on May 8, 2019

    @youlookwhat
    Owner

    严格来说需要加,可以加上volatile 关键字修饰。

    被volatile修饰的变量不参与指令重排, 在操作volatile变量时 在变量操作之前的代码一定是执行完毕并且是可见的, 在变量操作之后的代码一定是还没有被执行的。

  2. beautifulrainday commented on Apr 16, 2020

    @beautifulrainday

    应该是要的把

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions