mardi 30 octobre 2018

While loop will not terminate without "usleep()" or "printf"

I am curious to know if anybody knows why a simple while loop in c++ will not terminate without either a "usleep" or "printf"?

I have a boolean value that has its value changed externally, which its value is designed to terminate a while loop. I have also tried this and it fails:

if (!run) { break; }

It works perfectly fine with one of "usleep" or "printf" in the loop.

I have a gut feeling it is something to do with an interrupt, but not certain why.

while (run)
{
     // Do something

     // usleep OR printf
}

While i can easily do "usleep(0)" and it works, I am quite curious as to why this happens. My system is Ubuntu 16.04, running C++11 (GCC/G++ 5.4).

Thanks, CaptainJL

Aucun commentaire:

Enregistrer un commentaire