简体   繁体   中英

Operations on non atomic primitive variables

Reads and writes on long and double are not atomic. What's the worst that can happen if multiple threads access them simultaneously? Garbage values, or something more sinister?

Depends on what operations. If you're only reading them, then nothing bad would happen. Mixing reads/writes without synchronization of some sort, though, is almost always asking for trouble.

根据您使用不可靠变量的方式,您可能会得到可能非常险恶的垃圾值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM