Question: Challenge Problems Implementing Barriers with Semaphores ( intro to OS ) You are given a system that has semaphores, like the ones that we have
Challenge Problems
Implementing Barriers with Semaphores ( intro to OS )
You are given a system that has semaphores, like the ones that we have studied in class. These semaphores have three functions you can call:
sem_init: Sets the initial value of the semaphore. Note that it can be called only once, and must be before any other operation is done on that semaphore.
sem_P(): the normal semaphore P operation.
sem_V(): the normal semaphore V operation.
Using semaphores, you are to implement barriers, an important type of synchronization used in parallel computing systems. You will define a new type called barrier and write the code for the initialization (init_barrier) and arrive_barrier functions.
The initialization function, init_barrier(N) is called to set the number of processes that will use the barrier. A barrier is a way of synchronizing a fixed group of N processes (which is a group where you know the number, N of the processes involved in advance. Each process calls the arrive_barrier() operation and blocks until all N processes do the same. At that point, all the processes should be free to continue. Also, at this point, the barrier is reset and ready to use again.
// declare semaphores and state variables here: void init_barrier (int val) { } void arrive_barrier () { }
Please comment heavily for me to understand.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
