What are the pros / cons of using pthread_cond_wait or using a semaphore ?
I am waiting for a state change like this :
pthread_mutex_lock(&c
In your second snippet, you're getting the lock multitude of times, never releasing it.
In general, the state you're waintin on can be completely expressed by a semaphore, then you can use just that. A lock structure is smaller in size, and it requires less atomic operations to check/set/release.
Otherwise, if the state is complex, and different parts of the code wait on different conditions of the same variable (eg, here you want x<10; there you want y>x), use cond_wait.