如您所知,本书使用旧版Linux.它是2.6版本
atomic_t有“volatile int counter”.但是新Linux版本的atomic_t的“int counter”并不易变.为什么这种挥发性已经消失了?
解决方法
在这方面,挥发性物质的使用几乎永远不正确.
你可以在Semantics and Behavior of Atomic and Bitmask Operations阅读更多相关信息.
引用其中的一小部分:
* WARNING: atomic_read() and atomic_set() DO NOT IMPLY BARRIERS! *
Some architectures may choose to use the volatile keyword,barriers,or inline
assembly to guarantee some degree of immediacy for atomic_read() and
atomic_set(). This is not uniformly guaranteed,and may change in the future,
so all users of atomic_t should treat atomic_read() and atomic_set() as simple
C statements that may be reordered or optimized away entirely by the compiler
or processor,and explicitly invoke the appropriate compiler and/or memory
barrier for each use case. Failure to do so will result in code that may
suddenly break when used with different architectures or compiler
optimizations,or even changes in unrelated code which changes how the
compiler optimizes the section accessing atomic_t variables.* YOU HAVE BEEN WARNED! *
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。