Semaphores

Due:
11:00pm, Friday April 1, 2022

Description

For this assignment we will use semaphores to solve concurrency problems.

Questions

  1. Implement and test a solution to the fork/join problem. See fork-join.c for details. Add the call sleep(1) to the child to ensure it is working.

  2. Implement and test a solution to the rendezvous problem. The problem is as follows: you have two threads, each of which are about to enter the rendezvous point in the code. Neither should exit this part of the code before the other enters it. Consider using two semaphores for this task, and see rendezvous.c for details.

  3. Implement and test a general solution to barrier synchronization. Assume there are two points in a sequential piece of code, called P1 and P2. Putting a barrier between P1 and P2 guarantees that all threads will execute P1 before any one thread executes P2. Your task: write the code to implement a barrier() function that can be used in this manner. It is safe to assume you know N (the total number of threads in the running program) and that all N threads will try to enter the barrier. Again, you should likely use two semaphores to achieve the solution, and some other integers to count things. See barrier.c for details

Turning in the Assignment

For this assignment, you must turn in a zip file of a directory named assignment7.zip containing the following files:

  1. fork-join.c
  2. rendezvous.c
  3. barrier.c

Submit the zip file to the appropriate folder on D2L.