samedi 31 décembre 2016

Is atomic_compare_exchange_weak preferable over the strong version even in a long loop?

Suppose I use CAS inside a loop that contains a number of operations other than the CAS. The loop runs until the CAS succeeds. Should I use the weak version of CAS? Or will it be non cost effective to redo all the loop's operations in case the CAS spuriously fail, and I'd better use the strong version of CAS to ensure repeating the loop only if the CAS really had to fail (because object != expected)? Or is there no theoretical answer and I should try both versions and compare their performance?

Aucun commentaire:

Enregistrer un commentaire