Fixed unlocking if pthread_join fails.