Function to interrupt thread