Question: Objective You will learn how to use POSIX threads and their advanced synchronization feature. The Problem A university computer science department has two teaching assistants
Objective
You will learn how to use POSIX threads and their advanced synchronization feature.
The Problem
A university computer science department has two teaching assistants TAs who help undergraduate students with their programming assignments. Their office is rather small and has room for only two undergraduate students at a time. In addition, there are two chairs in the hallway outside the office where students can sit and wait if both TAs are helping other students. If a student arrives and finds both TAs assisting other students, the student sits on one of the two chairs in the hallway and waits. If no chairs are available, the student will come back at a later time.
Your program should track the actions of the students requesting help. It will represent each of them in a separate thread created by your main program. This thread will synchronize with other threads to ensure that the TA office will never contain more than two students and no more than two students will ever wait outside. To achieve that goal, they must use Pthread mutexes and condition variables. Solutions using semaphores will not be accepted.
YOUR PROGRAM
Your program will read all its input parameters from theredirectedstandard input. Each input line will describe a student seeking help and will contain three quantities representing:
A A name that will never contain spaces,
B The number of minutes elapsed since the arrival of the previous student, and
C The number of minutes the student will spend with a TA
One possible set of input could be:
Alice
Bob
Carolina
Dean
Your program should print out a descriptive message including the student's name every time a student:
A Arrives at the TA office;
B Leaves without waiting to get help;
C Starts getting help; and
D Leaves the TA office after being helped.
At the end, your program should display:
A The total number of students that got help;
B The number of students that left without getting help; and
C The number of students that had to wait.
NONDETERMINISTIC OUTPUTS
You will notice your program will produce nondeterministic outputs each time two events happen simultaneously, say, when a student arrives just when another leaves. These nondeterministic outputs occur because we do not control how our Pthreads are scheduled. The sole way to guarantee a deterministic output is to come up with input data that generate schedules where each event happens at a different time.
Pthreads
Don't forget the Pthread include:
#include
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
