// Shared by both threads pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; int x = 5; int y = 10;
Now the common statement executed by both threads is protected by the mutex:
... pthread_mutex_lock(&m); x = x + y; pthread_mutex_unlock(&m); ...