dimanche 29 avril 2018

Is there ever a difference between compare_exchange_strong and compare_exchange_weak on x86_64?

I am aware of the semantic difference between compare_exchange_strong and compare_exchange_weak; this question concerns the specific implementation on x86_64.

I compiled both of the following two programs on my x86_64 machine with gcc 5.4.

include <atomic>

std::atomic<int> foo;
int main(){
    int expected = 0;
    int desired = 1;
    foo.compare_exchange_strong(expected, desired);
}


#include <atomic>

std::atomic<int> foo;
int main(){
    int expected = 0;
    int desired = 1;
    foo.compare_exchange_weak(expected, desired);
}

When I disassembled the two programs using objdump -d, the output is identical.

Is this generally / reliably true on x86_64, or will I see differences across compiler versions or memory orders?

Aucun commentaire:

Enregistrer un commentaire