Restructured the signal-handling code to allow thread-specific behaviour for the timeout mechanism.