Why java.util.concurrent.atomic.AtomicBoolean is internally implemented with int?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 09:53:48

AFAIK, int is the smallest type CAS operations can be implemented across different machine types.

Note: as object allocations are 8 byte aligned, using a smaller type wouldn't save any memory.

This probably is to be able to base several of the Atomic classes on the same base (Unsafe), which uses integer and provides the compare and swap operation.

Concurrency in Practice provides a good explanation of the inner workings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!