Question: Question 1 (1 points): Consider the following incomplete C code that uses the POSIX threading API: Time remaining: 3 pthread_mutex_t lock; pthread_cond_t cv; // condition

Question 1 (1 points): Consider the following incomplete C code that uses the POSIX threading API: Time remaining: 3 pthread_mutex_t lock; pthread_cond_t cv; // condition variable int values[2]; int have_values[2] = {0, 0); void SetValue(int index, int new_value) { pthread_mutex_lock(&lock); values[index] = new_value; have_values[index] = 1; if pthread_cond_broadcast (&cv); pthread_mutex_unlock (&lock); void WaitForAndGetBothValues(int *values_copy) { pthread mutex lock (&lock); while (!have_values[0] || !have_values[1]) { pthread_cond_wait(&cv, &lock); values_copy[0] = values[0]; values_copy[1] = values[1]; pthread_mutex_unlock (&lock); Ignore any minor syntax errors above and assume all condition variables, locks, etc. are appropriately initialized before any of the above code is run. The WaitForAndGetBothvalues function is intended to wait for Setvalue to be called with both index 0 and index 1, then return the resulting contents of the values array (by copying it into an array located using the supplied pointer). Which of the following would be best to place in the blank above to make WaitForAndGetBothvalues behave correctly? A. O pthread_mutex_lock(&lock) != 0 B. have_values[1 - index] C. O cv == false D. O pthread_cond_wait(&cv, &lock) == 0 E. cv == true F. ! have_values[0] || !have_values[1]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
