gpt4 book ai didi

linux - linux内核中的原子操作是没有 dentry 的吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:33:10 28 4
gpt4 key购买 nike

根据 atomic_ops.txt在 Linux 内核中,

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! ***

如果无论如何都必须使用障碍,那有什么用呢?

最佳答案

atomic_t 和“普通”变量之间的区别是前者允许原子更新(即,其他线程看到旧值或新值,但没有中间状态)和原子读-和更新操作。换句话说,atomic_t 允许多个线程访问同一个变量。

需要内存屏障来处理不同变量之间的依赖关系。

关于linux - linux内核中的原子操作是没有 dentry 的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23735887/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com