2010-03-19 85 views

回答

2

这一切都取决于实施。 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 

实现这样对你的回答很可能是“是”。

+0

+1谢谢Kenny。所以_OSCompareAndSwap64包含cmpxchg8b,我想它应该免疫ABA问题。 – Viet 2010-03-19 15:57:57

相关问题