原子属性线程安全吗? [英] Is an atomic property thread safe?
问题描述
我已经回答了许多有关原子和非原子性质的答案.但是我无法理解原子属性是否是线程安全的?请举例说明.
I have gone through many answers about atomic and non-atomic properties. But I'm not able to understand whether atomic properties are thread safe? Please explain it with an example.
推荐答案
是
一个/一个原子属性是线程安全的.这就是原子性的意思.
Yes
an / one atomic property is thread-safe. That is what atomicity stands for.
注意
但是两个原子属性彼此之间都不是线程安全的,原子属性的内容也不是线程安全的. (听起来有点令人困惑,但是已经说过了)
But neither are two atomic properties thread-safe in regards to each other nor are the contents of an atomic property thread-safe. (sounds a bit confusing but has be said)
这意味着您始终可以确保从属性中读取功能完整的值,没有损坏的指针或中介null或任何其他内容.
That means that your are always guaranteed to be able to read a fully functional value from the property, no broken pointer, or intermediary null or whatsoever.
但是,您不能保证该atomic属性中的值是线程安全的.那是一个完全不同的话题.
BUT you are not guaranteed that the values inside that atomic property are thread-safe whatsoever. That is a completely different topic.
使用原子类的所有属性完全不会使该类本身具有线程安全性.
Making all properties of a class atomic will not at all make the class itself thread-safe.
这篇关于原子属性线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!