Added a watchdog mechanism to break out of the wait4 call in case it didn't return properly (can happen at thread exit).