Tynan Wilke wrote:
Thanks for the quick response. I looked at the assembly code, and found it a bit strange. Here are the two while loops in comparison: while ( g_counter == 0 ); -O0 0x08048567 <main+102>: mov 0x80497f8,%eax 0x0804856c <main+107>: test %eax,%eax 0x0804856e <main+109>: je 0x8048567 <main+102> -O1 0x0804853a <main+102>: mov 0x80497f8,%eax 0x0804853f <main+107>: test %eax,%eax 0x08048541 <main+109>: je 0x8048541 <main+109> <--- jumping to itself, so only testing the first time through So, the -O0 is doing what I would expect, but the -O1 version IS testing the global variable the first pass, but then never jumping back to the 0x0804853a to retrieve the new global value and then re-test. Is this right?
Yes. Since the global variable is not changed in the loop, it's not necessary to look at it again. Andrew.