CPS801 Assignment 3 (4 marks)

Due Date: During the Lab Period,  February 2

 

1- Explain the general problems of the programs that solve the race condition problem by using busy waiting  methods.
(0.5 mark)

2- For the producer-consumer problem that used sleep and wakeup (Fig 2-27 of the book) describe the race condition scenario in which both producer and consumer may sleep forever. (0.5 mark)

 

3- Write a shell script (or a program) that produces a file of sequential numbers by reading the last number in the file, adding 1 to it, and then appending it to the file. Run one instance of the script/program in the background and one in the foreground, each accessing the same file. By looking at the resulting numbers, explain how the race condition manifests itself when running these scripts/programs.  Modify the script/program to prevent the race (hint: for shell script use ln file  file.lock to lock the data file)  (1 mark)

 
4- By using any method of your choice (if you are familiar with semaphore you can use one of the variations of Unix semaphores) modify the program of  Exp 6.1 (posted on the course web page) to synchronize the threads in the way that  each of them finishes writing  of the all assigned words without interrupting by other threads. For example the output of  p61  f  a  c  e  should be as the following:

 f to be printed 2 times.
a to be printed 5 times.
c to be printed 2 times.
e to be printed 5 times.
f f a a a a a c c e e e e e 

Hint: you can use any methods based on busy waiting , locks and etc. but if you want to use semaphore include this header file  in your program that can be run on jupiter . (1 mark)

 

Submission: