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 continue.

 (5pts) Consider the following multi-threaded C code: 1: // Barrier waits

(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: b->n n; 5: b->count = 0; 6: sem_init(&b->semaphore, 0 /*not shared*/, n /*init val*/); 7: } 8: void barrier_wait(barrier_t* b) { 9: int new_count atomic_increment(&b->count); 10: if(new_count b->n) { 11: sem_post(&b->semaphore); 12: } 13: sem_wait(&b->semaphore); 14: 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

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!