CS314_Project_01

advertisement
CS314-001 Operating Systems
Programming Project #1 Description
Spring 2016
Project Due: 9:30 A.M. on February 25th.
1. Introduction
In this phase of the programming assignment, we will develop a solution for “adder & subtracter with
multiple readers problem”.
2. Program specifications
Your final program must satisfy the following requirements:
(1) The main (parent) process creates a chunk of shared memory
(2) The main (parent) process creates four child processes. The first child becomes the "Adder"
("A"), and the second, third, and fourth child becomes the first, second, and the third reader
(R1, R2, and R3 respectively).
(3) Each of the five processes needs to wait until all the other processes are created and active.
(4) When the main (parent) process sees that all four child processes are active, then it becomes
the "Subtracter" ("S").
(5) Each of Adder and Subtracter repeats their jobs (“jobs” are defined later) “NUM_REPEATS”
times (“NUM_REPEATS should be declared as a label using “#define” at the beginning of your
cpp source code file).
(6) The three readers (R1, R2 and R3) repeat until both Adder and Subtracter complete their jobs.
(7) When both the Adder and Subtracter complete their jobs, the three readers terminate.
(8) When the Subtracter completes its jobs, it terminates.
(9) The parent process waits until all the other four child processes (A, R1, R2, and R3) to terminate.
(10) The parent process deletes the shared memory.
1
(11) The parent process terminate (the parent always the last one to leave).
Definitions of "jobs":
Adder: (a) It displays "A is in the CS" when it enters the CS.
(b) It updates the content in the shared variable ("counter") by adding 1 to it.
(c) It waits for a random time (0-1 sec.).
(d) It displays "A is leaving the CS" immediately before it leaves the CS.
Sub: (a) It displays "S is in the CS" when it enters the CS.
(b) It updates the content in the shared variable ("counter") by subtracting 1 from it.
(c) It wait a random time (0-1 sec.).
(d) It displays "S is leaving the CS" immediately before it leaves the CS.
Reader: (a) It displays "Rx is in the CS" when it enters the CS (x is the reader ID).
(b) It reads the contents in "counter" and displays it as "Rx reads N", where N is the
content in the counter.
(c) It displays "Rx is leaving the CS" immediately before it leaves the CS.
(d) It checks if it should repeat more.
(e) It wait a random time (0-1 sec.).
3. Requirements
Your program must follow the following requirements:
(a)
(b)
(c)
(d)
No starvation should occur.
No violation of mutual exclusion should occur for Adder and Subtracter.
No deadlock should occur (all the processes should be always completed).
Multiple readers should be able to enter the critical section (at least several times in a
program execution).
(e) Semaphore(s) and shared memory created in your program should be deleted by your
program before it terminates.
4. Objectives
This programming is designed for the following objectives
(1) To understand the concept of process
(2) To understand the concept of inter process communication (IPC)
(3) To understand the concept of process synchronization
(4) To develop system programming skills to manage race condition and critical section
(5) To develop programming skills to avoid process starvation and deadlock
2
(6) To have UNIX system programming experience
(7) To be familiar with UNIX-based operating systems
5. Grading Criteria
1. Any compile-time error (-80%)
2. Minor run-time error: -5% (for each)
3. Major run-time error (failing the meet any of requirement (a) through (d): depends.
4. Program style (program structure and in-line comments): 10%
6. Guidelines for acceptable activities
1. Using external references (web sites, programming reference books, and etc.): Allowed.
2. Exchanging ideas with your classmates: Not recommended but acceptable
3. Exchanging source codes with your classmates: Not acceptable (absolutely not allowed, no
matter how many lines of the codes).
4. Requesting someone else (but yourself) to write any code for you for this assignment: Not
acceptable (absolutely not allowed). Exams may ask you some questions regarding your code.
If you fail to convince Dr. Fujinoki your work, your assignment credit can be cancelled).
8. Required submission
Program softcopy (should be e-mailed to the instructor, as “project1_your3digits.cpp”) and hard
copy by the project due.
9. Late Submission


Penalty of -10% will be given for every 24 hours after the due (i.e., -10% for a submission
within the first 24 hours after the due).
Submission more than 48 hours after the due will not be accepted.
_________________________________________________________________________________
CS314 Operating System, Programming Project #1
3
Download