mardi 6 novembre 2018

do compare_exchange based loop benefit from pause?

In a CAS based loop, for example the one below, is the use of pause beneficial on x86?

void atomicLeftShift(atomic<int>& var, int shiftBy)
{
    While(true) {
        int oldVal = var;
        int newVal = oldVal << shiftBy;
         if(compare_exchange_weak(oldVal, newVal));
             break;
        else
            _mm_pause();
    }
}

Aucun commentaire:

Enregistrer un commentaire