Fix race for pthread-based wait/signal mechanism.