CSE 330 - Operating Systems
Spring 2020
Project #4
Due: April 20
(groups of 2, use same group as before, unless there is a problem) 

A semaphore based program:

Write the program that does the following. Use semaphores.

1.       The main (parent) thread initializes an array of 3 integers initialized to zero.

2.       The parent creates 3 children. Child i adds 1 to array[i], where i = 0, 1, 2. Order not important.

3.       The parent waits for the children to finish adding, and then prints the values in the array.

4.       The children wait for the parent to finish printing and then repeats (adds 1 to an element of the array)

5.       Continues forever

Option 1:

Implement the above program using semaphores.

Option 2: (more points)

Do option 1 first, and if it all works, expand the solution to N threads. N is a runtime parameter, and assume N is lower than 20. The best solution will use a minimal number of semaphores.

Submission and Grading:

Submit only 1 of option 1 or 2, and state which one, in your comments.

Your project must consist of 5 files

1.      TCB.h (uses ucontext.h)

2.      q.h (includes TCB.h)

3.      threads.h (includes q.h)

4.     sem.h (includes threads.h)

5. proj-4.c (includes sem.h) must contain your name(s) in comments @ beginning

(make sure the compile command, gcc proj-3.c does the correct compilation).

All 5 files are to be ZIPPED into one zip or gzip file.

 Upload to Canvas. Make sure your names are in comments in your code. One submission for each group, please.