Prevent infinite loop to start an unstoppable thread