Java内存模型FAQ(六)没有正确同步的含义是什么?
2021/12/3 7:10:09
本文主要是介绍Java内存模型FAQ(六)没有正确同步的含义是什么?,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
没有正确同步的代码对于不同的人来说可能会有不同的理解。在Java内存模型这个语义环境下,我们谈到“没有正确同步”,我们的意思是:
-
一个线程中有一个对变量的写操作,
-
另外一个线程对同一个变量有读操作,
-
而且写操作和读操作没有通过同步来保证顺序。
当这些规则被违反的时候,我们就说在这个变量上有一个“数据竞争”(data race)。一个有数据竞争的程序就是一个没有正确同步的程序。
《Java内存模型FAQ(一) 什么是内存模型》https://shimo.im/docs/3wGJrJGJgRppK8CT/
《Java内存模型FAQ(二) 其他语言,像C++,也有内存模型吗?》https://shimo.im/docs/6wwYdRjdT8YJcQtw/
《Java内存模型FAQ(三)JSR133是什么?》https://shimo.im/docs/Cpv88pvvJxPjwkcY/
《Java内存模型FAQ(四)重排序意味着什么?》https://shimo.im/docs/9q3tD9GJvJhCqqpj/
《Java内存模型FAQ(五)旧的内存模型有什么问题?》https://shimo.im/docs/kVCvTJ96pJTdqr6G/
原文
What do you mean by “incorrectly synchronized”?
Incorrectly synchronized code can mean different things to different people. When we talk about incorrectly synchronized code in the context of the Java Memory Model, we mean any code where
-
there is a write of a variable by one thread,
-
there is a read of the same variable by another thread and
-
the write and read are not ordered by synchronization
When these rules are violated, we say we have a data race on that variable. A program with a data race is an incorrectly synchronized program.
这篇关于Java内存模型FAQ(六)没有正确同步的含义是什么?的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?