Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SummerXSH opened this issue May 6, 2019 · 2 comments

Comments

@SummerXSH
Copy link

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

@youlookwhat
Copy link
Owner

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

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

@SummerXSH SummerXSH reopened this May 8, 2019
@beautifulrainday
Copy link

应该是要的把

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants