Unlock the mutex before ending thread life

Thread destruction was broken otherwise, because the returning thread
didn't unlock the mutex.