Updated signal handling code. This code trades explicit locks (which, by the way, are a bad idea when used in a signal handler) for synchronous operations.