Fix crash on Linux if sem_wait() is interrupted.

Patch by Andrew MacPherson.