讲解CS 3413留学生、CS编程讲解、辅导C语言、辅导讲解CS/C++程序、C/C++设计辅导
- 首页 >> 其他CS 3413
Assignment 4
Due Date: October 10th, 2018 at 9:30 am
ASSIGNMENT IS TO BE COMPLETED INDIVIDUALLY BY ALL STUDENTS!
Solutions to your problem should be submitted via D2L. Your solution is to be
written in C using pthreads.
Student demand for help with their assignments has increased. As such, Ken has decided
to outsource student assistance. He has hired 4 TAs to assist students. When students
want help they go to the sunken lounge where a TA will help them. TAs live a simple life
of just helping students and sleeping. If there is a student wanting help, they help them.
To help a student requires a random amount of time between 3 and 30 seconds. If there
are no students requiring help, the TA sleeps but wakes up if a student arrives for help!
Each student, when they arrive, checks to see how busy it is. If a TA is sleeping, then the
student wakes up the TA. If all the TAs are busy helping students, then the student takes
a seat to wait their turn (first come first served) … if there is one available. If there is no
free chair, then the student leaves to go try and do the assignment on their own.
TAs are paid for a set number of seconds to help students as per their contract. When a
TA reaches their hour limit they stop helping students. Note: TAs are nice people – so
they will finish helping a student if their time is up while they are helping a student! The
program ends when ALL of the TAs are finished their required number of seconds.
Note: For your solution you should use a pthread for each of the TAs. You are going to
need to use pthread_mutex in order to help you complete this assignment!
There are always 4 TAs. How frequent a student arrives for assistance is chosen at
random between 0 and n seconds. See the rand() system call. Your program will also
take as a command line parameter the number of chairs in the sunken lounge. So
./a.out –c 5 –t 200 –n 12
Will specify 5 chairs in the sunken lounge, each TA has 200 seconds of set time to help
students, and with students randomly arriving for help between 0 – 12 seconds.
Output of the program will consist of the following:
When a student is turned away from a full sunken lounge:
o Student x is not taking a chance in the lab with
their assignment.
When a student takes a seat in the sunken lounge:
o Student x is waiting for a TA.
When a student is finished getting help:
o Student x is going to pass this assignment!
x in each of these output lines is the number of the student. Numbers are assigned
sequentially starting at 1 to students as they arrive to check the sunken lounge