سؤال

هل OsCompareAnswap محصن ضد ABA مشكلة مثل CMPXCHG8B؟

هل كانت مفيدة؟

المحلول

كل هذا يتوقف على التنفيذ. OsCompareAnswap* ليست سوى واجهة تضمن مشغل CAS ذري (إذا كانت وحدة المعالجة المركزية تدعمها).

ل 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

لذا فإن الجواب لك ربما هو "نعم".

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top