我可以使用 #include <stdatomic.h>
吗?和 atomic_thread_fence()
与 memory_order
来自 Linux 驱动程序(内核空间)中的 C11,还是我必须使用内存屏障的 Linux 函数:
- http://lxr.free-electrons.com/source/Documentation/memory-barriers.txt
- http://lxr.free-electrons.com/source/Documentation/atomic_ops.txt
使用:
- Linux 内核 2.6.18 或更高版本
- GCC 4.7.2 或更高版本
最佳答案
如果您正在编写内核代码,您应该使用 C 来编写,并且使用当前内核(附带 gcc)所需的 C 版本来编写。如果你想让它被主线接受(或者把它写得好像它会被接受一样),你应该使用 Linux 函数。您还会发现它们的工作没有意外的惊喜,并且您将获得更好的调试帮助。
总结:使用linux函数。
关于我可以在 Linux 驱动程序中使用 C11 的 <stdatomic.h> 吗?还是必须使用内存屏障的 Linux 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21497761/