mercredi 26 octobre 2016

Does the C++11 memory model allow hoisting relaxed atomic loads out of loops?

Consider the following code:

#include <stdatomic.h>

extern _Atomic int i;

void g(void);

void f(void)
{
    while (!atomic_load_explicit(&i, memory_order_relaxed))
        g();
}

I'm looking for a citation from the C++11 or C11 standard that says that the compiler is not allowed to transform the loop into

    if (!atomic_load_explicit(&i, memory_order_relaxed)) {
        while (1)
            g();
    }

I've seen some discussion here but nothing conclusive.

Aucun commentaire:

Enregistrer un commentaire