I'm trying to figure out if I need to use volatile or not. All of the examples I've seen so far seem to be set up as some small loop is checking the state of a variable to see if it should exit the loop but that variable is only changed from some other thread (not inside the loop).
This makes sense, since the value could feasibly be read on the 1st iteration of the loop and then not read on subsequent iterations. However, this also only makes sense to me if the loop is small. If a whole lot of stuff is done inside the loop, the compiler may have no choice but to read it every time, since it may need to use the register it is caching the loop constraint variable in, right?
If I have some loop that does A LOT of stuff, like a game loop for example, if somewhere in that loop, I'm checking the value of some global that another thread updates, is it really necessary to make that global volatile? Everything I've read says yes, but everything I've read only presents extremely simplistic scenarios.