What bothers me is that the OCaml code looks so harmless:
static void st_masterlock_acquire(st_masterlock * m)
{
pthread_mutex_lock(&m->lock);
while (m->busy) {
m->waiters ++;
custom_condvar_wait(&m->is_free, &m->lock);
m->waiters --;
}
m->busy = 1;
pthread_mutex_unlock(&m->lock);
}
How is this bug not more common with such a simple invocation?