像CMPXCHG8B一样,OSCompareAndSwap对ABA问题免疫吗?
发布于 2010-03-19 21:03:23
这完全取决于实现。OSCompareAndSwap*只是一个保证原子CAS运算符的接口(如果CPU支持它的话)。
对于x86,64位的此函数实现为
_OSCompareAndSwap64:
pushl %edi
pushl %ebx
movl 4+8(%esp), %eax #; low 32-bits of oldValue
movl 8+8(%esp), %edx #; high 32-bits of oldValue
movl 12+8(%esp), %ebx #; low 32-bits of newValue
movl 16+8(%esp), %ecx #; high 32-bits of newValue
movl 20+8(%esp), %edi #; ptr
lock
cmpxchg8b 0(%edi) #; CAS (eax:edx, ebx:ecx implicit)
sete %al #; did CAS succeed? (TZ=1)
movzbl %al, %eax #; clear out the high bytes
popl %ebx
popl %edi
ret所以你的答案可能是“是”。
https://stackoverflow.com/questions/2476996
复制相似问题