[英]Atomic read/write for function pointer in C?
I am working on some code in C that is run on Windows as well as other platforms. 我正在研究Windows和其他平台上运行的C语言代码。 I know of functions such as InterlockedExchangePointer to atomically read/write a data pointer, and I'm sure there's something similar for other platforms, but how can I do that with a function pointer in a portable way?
我知道诸如InterlockedExchangePointer之类的函数可以原子地读取/写入数据指针,而且我敢肯定其他平台也有类似的东西,但是我该如何使用可移植的方法使用函数指针呢? Is it possible or do I need a lock or a memory barrier or something?
是否可以,或者我需要锁或内存挡板之类的东西?
C11 atomics is the standard-based thing, but not all compilers support it. C11 原子是基于标准的事物,但并非所有编译器都支持它。
GCC 4.1+, as well as compilers like clang and ICC which strive for compatibility with it support __sync
builtins . GCC 4.1+以及像clang和ICC这样的努力争取与之兼容的编译器都支持
__sync
。
I have some code which provides a common API that you might be interested in. 我有一些代码提供了您可能感兴趣的通用API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.