/* x, y and mtx are shared */ /* the programmer believed that eventually x equals y, but now x==1, y==0 and only those two processes run: */ /* Thread 1 */ │ /* Thread 2 */ char loop = 1; │ char loop = 1; while(loop) { │ while(loop) { pthread_mutex_lock(&mtx); │ pthread_mutex_lock(&mtx); if (*x==0 && *y==0) { │ if (*x==1 && *y==1) { /* do business logic */ │ /* do business logic */ loop = 0; │ loop = 0; } │ } pthread_mutex_unlock(&mtx); │ pthread_mutex_unlock(&mtx); } │ }