Question: COMPLETE THE FOLLOWING PROGRAM IN C: Today you will implement one last synchronization mechanism: barriers ! Recall that barriers allow us to group threads together
COMPLETE THE FOLLOWING PROGRAM IN C:
Today you will implement one last synchronization mechanism: barriers! Recall that barriers allow us to group threads together so that synchronization points can be established. This is useful when a computation is broken into multiple stages and each stage must be completed before the next can begin.
The given header file, barrier.h, contains an empty barrier struct and three function prototypes. Your task is to implement the struct and the three functions. Implementations for the functions should be added to barrier.c.
The tester.c file contains code to test your barrier implementation and can be compiled with the provided Makefile. Do not modify tester.c. As usual, ensure your implementation does not produce any memory errors when run!
barriers.h:
#ifndef __3100_BARRIERS_H_
#define __3100_BARRIERS_H_
#include
typedef struct
{
// TODO implement me!
} barrier;
/* Initializes the barrier and all of its fields.
* sz - number of threads that can wait on this barrier. */
int barrier_init(barrier* b, int sz);
/* Destroys the barrier and frees memory, if necessary. */
int barrier_destroy(barrier* b);
/* Blocks current thread until all other threads have reached the barrier. */
int barrier_wait(barrier* b);
#endif
barrier.c:
// TODO implement barrier functions here!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
