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

07.三大性质总结:原子性、可见性以及有序性 #12

Open
akwolf opened this issue Nov 22, 2018 · 1 comment
Open

07.三大性质总结:原子性、可见性以及有序性 #12

akwolf opened this issue Nov 22, 2018 · 1 comment

Comments

@akwolf
Copy link

akwolf commented Nov 22, 2018

原文:如果2和3进行了重排序的话,线程B进行判断if(instance==null)时就会为true,而实际上这个instance并没有初始化成功,显而易见对线程B来说之后的操作就会是错得。

在解释双重加锁的时候提到指令重排序后,如果先分配内存地址而不是先初始化,内存地址现在已经有值,那么if(instance==null)是不是应该返回为false

@zhumayer
Copy link

是的,我也觉得这里写错了。
参考https://blog.csdn.net/glory1234work2115/article/details/50814419

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

2 participants