Made a mistake in the implementation since I did not read http://linux.die.net/man/3/pthread_cond_wait.
The cond_wait should relock upon waking.