Added subroutine for thread polling with timeout