I have some C++ code that uses a local-scope, program-lifetime object, e.g.
void testFunction(int arg) {
static Tested tested(0);
tested.use(arg);
}
which built fine with older versions of GCC. With GCC 8.2.0, I get a puzzling warning at link time:
warning: legacy compatible __sync_synchronize used. Not suitable for multi-threaded applications
It points the line defining tested, and indeed there is a call to __sync_synchronize() that has been generated by the compiler. I guess it is there to ensure that no two threads could run the initializing code at the same time and have the lazy initialization produce the same result as if there was load-time initialization.
Issue is reproduced with this implementation of the Tested class:
class Tested {
int sum;
public:
Tested(int init) : sum(init) {}
void use(int arg) {
sum += arg;
}
int current() const {
return sum;
}
};
This code is expected to run on a mono-thread embedded platform.
Am I right believing that the warning is not relevant for me ?
What can I do (beside stopping using the static object) to get rid of the warning message ?