0

これは私のコードです(ただし、関連のない部分をいくつか削除しました):

#include <atomic>
#include <math.h>
#include <iostream>

using namespace std;

struct Profiler
{
private:
    Profiler() {}
    Profiler(const Profiler& other) {}
    Profiler operator = (const Profiler& other) { return *this; }

public:
    static atomic_ullong a;
    static atomic_ullong b;
};

atomic_ullong Profiler::a = { (unsigned long long)0 };
atomic_ullong Profiler::b = { (unsigned long long)0 };

bool func()
{
    Profiler::a++;
    float det = rand();

    if (abs(det) < numeric_limits<float>::epsilon())
        return false;

    Profiler::b++;

    return true;
}

int main(int argc, char** argv)
{
    bool result = func();

    cout << result << endl;

    system("pause");

    return 0;
}

これは、デバッグ モードで適切にコンパイルおよび実行されます。ただし、リリース モードに切り替えた後、実行時にアクセス違反の例外が発生し続けます。atom_ullongをatomic_ullongまたはatomic_uintに変更しても問題なく動作するのはとても奇妙です。しかし、この 2 つの長さだけでは十分ではありません。では、なぜこれが起こっているのか、そしてそれを解決する方法を知っている人はいますか? 助けてください!

4

1 に答える 1