mardi 4 avril 2017

How to avoid thread safe static initialization in C++

Here's sample code:

static bool isIPhone6()
{
    static bool ret = "iPhone 6"==SystemUtil::deviceName();
    return ret;
}

It's pretty simple, but because statics are now threadsafe c++ compiler generates lots of trash that I don't want to see around my static variable. Is there a way to avoid all that baggage without resorting to workarounds or compiler switches? Basically, is there a way to get pre c++11 static initialization that wasn't thradsafe per function?

Aucun commentaire:

Enregistrer un commentaire