你好,我刚开始接触gcc内置的原子函数,并正在使用test-and-set
函数。你可以在这里找到参考文档。
以下是问题描述:
我已经写了下面的代码:
#define bool int
#define true 1
#define false 0
int main() {
bool lock = true;
bool val = __sync_lock_test_and_set(&lock, true);
return 0;
}
我的意图是检查__sync_lock_test_and_set
的汇编指令。我已经使用了:
gcc -S [filename].c
结果如下:
.file "test_and_set.c"
.file "test_and_set.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $16, %esp
movl $1, -8(%ebp)
movl $1, %eax
xchgl -8(%ebp), %eax
movl %eax, -4(%ebp)
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 4.8.1"
然而,我找不到test_and_set指令在哪里...
正如您所见,我正在使用gcc-4.8.1,并且环境是MAC OSX 10.10(我确定这个gcc不是Apple提供的。我自己编译的)
谢谢!
xchgl
... 我明白了,谢谢! - VELVETDETH