1. Locks
-
mutex = mutual exclusion, only one thread can hold the lock at any time
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; ... Pthread_mutex_lock(&lock); // wrapper; exits on failure balance = balance + 1; Pthread_mutex_unlock(&lock);
How to implement?Issues: Correctness (even on multiprocessors), Performance (time overhead), Fairness (no starve)