Is the following comparison an atomic action? I.e., can it be reduced to a single CPU instruction?
char flag = 2;
for(;;)
{
if (!flag) // <-- this
break;
// sleep
}
Here's what I'm doing:
int main()
{
sf::Mutex Mutex;
char flag = 2;
coordinatorFunction(flag);
for(;;)
{
if (!flag)
break;
// sleep
}
}
void workerFunction(void* a)
{
char* p = static_cast<char*>(a);
// work
GlobalMutex.Lock();
--*p;
GlobalMutex.Unlock();
}
void coordinatorFunction(char& refFlag)
{
sf::Thread worker1(&workerFunction, &refFlag);
sf::Thread worker2(&workerFunction, &refFlag);
worker1.Launch();
worker2.Launch();
}