Question
(5pts) Consider the following multi-threaded C code: 1: // Barrier waits for n threads to call barrier_wait before 2: // allowing the threads to
(5pts) Consider the following multi-threaded C code: 1: // Barrier waits for n threads to call barrier_wait before 2: // allowing the threads to continue. 3: void barrier_init(barrier_t* b, unsigned int n) { 4: 5: 6: 7: } b->n = n; b->count = 0; sem_init(&b->semaphore, 0 /* not shared */, n/*init val*/); 8: void barrier_wait(barrier_t* b) { int new_count atomic_increment (&b->count); 9: 10: if(new_count b->n) { 11: sem_post(&b->semaphore); 12: } 13: 14: sem_wait(&b->semaphore) sem_post(&b->semaphore); 15: } Describe and fix any bug(s) you see, if any.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Answer There are a couple of potential issues with the given code Race Condition There is a race con...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Introduction to Algorithms
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
3rd edition
978-0262033848
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App