mardi 14 décembre 2021

Does this code cause data race condition?

I'm writing multi thread code on x64 windows msvc.
I don't want to use std::atomic because it flush write combined buffer.

static unsigned int value[100];

thread1

for(size_t i = 0 ; i < 100 ; i++)
{
    if( (value[i] & (1 << 1)) != 0 )
    {
        value[i] |= (1 << 2);
    }
}

thread2

for(size_t i = 0 ; i < 100 ; i++)
{
    if( (value[i] & (1 << 1)) != 0 )
    {
        value[i] |= (1 << 2);
    }
}

Aucun commentaire:

Enregistrer un commentaire