The following code exhibits certain race conditions. Please…
The following code exhibits certain race conditions. Please identify them and rearrange the code to correct them. If needed, you may add additional lines like pthread_mutex_lock, etc. #include #include #include pthread_mutex_t mutex;pthread_cond_t cond;int ready = 0; void* worker(void* arg) { printf(“Worker thread waiting…\n”); while (!ready) { pthread_cond_wait(&cond, &mutex); } printf(“Worker thread proceeding!\n”); return NULL;} void* signaler(void* arg) { sleep(1); printf(“Signaler thread signaling!\n”); pthread_cond_signal(&cond); ready = 1; return NULL;} int main() { pthread_t t1, t2; pthread_mutex_init(&mutex, NULL); pthread_cond_init(&cond, NULL); pthread_create(&t1, NULL, worker, NULL); pthread_create(&t2, NULL, signaler, NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond); return 0;}
Read DetailsPlease read each questions carefully before answering them….
Please read each questions carefully before answering them. Please reply to each section of the question separately. If you are asked to justify your answer, please justify why you chose that option over the others to get full credits. When you are asked to find the bug, please look for the significant synchronization/concurrency bug in the given part of the code. Please do not waste your time finding out syntax errors (if any).
Read Details