Question: We are writing a thread - safe queue. We are using a mutex lock and a condition variable nonempty. Our function dequeue ( ) should

We are writing a thread-safe queue. We are using a mutex lock and a condition variable nonempty. Our function dequeue() should block if the queue is empty (length ==0) until another threads adds a value to the queue and signals nonempty. Which of the following code fragments will accomplish this? We are writing a thread-safe queue. We are using a mutex lock and a condition variable nonempty. Our function dequeue() should block if the queue is empty (length ==0) until another threads adds a value to the queue and signals nonempty. Which of the following code fragments will accomplish this? pthread_cond_wait(&nonempty, &lock); if (length ==0){ pthread_cond_wait(&nonempty, &lock); } while (length ==0){ pthread_cond_wait(&nonempty, &lock); } do { pthread_cond_wait(&nonempty, &lock); } while (length ==0); All of the above None of the above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!