Fix some thread interruption race conditions.