Added SIGUSR1 handling for terminating a thread