...
If the value of i is cached, the while loop may never terminate, even on the program . When compiled on gcc with the -O optimization flag, the program fails to terminate even upon receiving a SIGINT.
| Code Block | ||
|---|---|---|
| ||
#include <signal.h>
sig_atomic_t i;
void handler(int signum) {
i = 0;
}
int main(void) {
i = 1;
signal(SIGINT, handler);
while (i) {
/* do something */
}
return 0;
}
|
...