Question: The below snippet of C code uses pthreads for concurrent execution. It uses a mutex M and a condition variable C to ensure that the
The below snippet of C code uses pthreads for concurrent execution. It uses a mutex M and a condition variable C to ensure that the run critical code function only executes when the condition boolean is true. L1: pthread_mutex_lock(&M); L2: run_critical_code (); L3: if (! condition) L4: pthread_cond_wait(&C, &M); L5: if (! condition) L6: pthread_cond_broadcast(&C); L7: pthread_mutex_lock(&M); Unfortunately, there are four bugs in the code that prevent it from working correctly. List each of the four bugs and describe how each bug affects programme execution. Write down a new version of the code snippet with the four bugs corrected
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
