How to provide a sequence of interleaving threads to show that a code breaks and doesn't provide perfect synchronization?
问题 I know what the following code does and I know why it is a broken code for synchronization as it has only one conditional variable while we need two but I don't know how to provide a sequence of interleaving threads for showing it doesn't work. Can you show why this code doesn't work with an example? 1 cond_t cond = PTHREAD_COND_INITIALIZER; 2 mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;; 3 4 void *producer(void *arg) { 5 int i; 6 for (i = 0; i < loops; i++) { 7 Pthread_mutex_lock(&mutex); 8