When setting a variable in a signal handler, use volatile. Really should avoid the whole issue, as indicated in the comment.