用于Linux 64位的Oracle(Sun)Studio 12.2 C / C ++ / Fortran编译器是否具有与gcc中提供的__sync_fetch_and_add函数等效的功能?我似乎无法在Sun文档中找到intel atomics的包装代码,也无法在Sun Studio安装中找到.h文件。这意味着要么我只是擅长搜索,要么它可能不存在,不确定是哪个。
我碰巧需要使用Sun C / C ++编译器访问intel i7上可用的任何原子硬件函数,例如Test-and-set,Compare-and-swap,Fetch-and-foo。
这很复杂,因为我不是汇编程序员,而且这是Sun编译器而不是GCC编译器,因此从gcc的开源实现复制asm代码不一定能够工作,最后它是64位编译器和硬件,因此容易找到的32位示例不一定能在64位系统上正常工作。
背景:目的是为多核实现一些需要这些特定硬件原子的并发程序。
感谢阅读。
答案 0 :(得分:4)
从Oracle文档中,您需要包含atomic.h并使用以下其中一项:
uint_t atomic_add_int_nv(volatile uint_t *target, int delta);
uint64_t atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t newval);
void atomic_or_32(volatile uint32_t *target, uint32_t bits);
......等等。
http://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hr06/index.html