Avoid infinite blocking on internalWait() by replacing cond_wait with cond_timedwait