make sure things are really finished

According to the docs, "spurious wakeups from the pthread_cond_wait()
function may occur", so make sure things are actually finished before
shutting down.