Question: Must be done in c Seeking TA Problem The computer science department runs a mentoring center to help undergraduate students with their programming assignments. The
Must be done in c
Seeking TA Problem
The computer science department runs a mentoring center to help undergraduate students with their programming assignments.
The lab has a coordinator and several TAs to assist the students. The waiting area of the center has several chairs. Initially, all the chairs are empty.
The coordinator is waiting for the students to arrive and all the TAs are waiting for students to be assigned by coordinator. A student who arrives at the center seeking help sits in an
empty chair in the waiting area and waits to be called for TAing. If no chairs are available, the student will come back at a later time. If the coordinator sees a student waiting, then the
coordinator wakes up an idle TA, if there is one, and assigns the student to the TA. If all the TAs are busy assisting students, the coordinator waits for a TA to be free and then
assigns a waiting student to the TA. A TA after assisting a student, waits for the next student to be assigned to him Using POSIX threads, mutex locks, and semaphores, implement a
solution that coordinates the activities of the coordinator, TAs, and the students. Some hints to implement this project are provided next.
Implementation Hints
Using Pthreads, begin by creating n students and m TAs as separate threads. (n and m are arguments to the program.)
The coordinator will run as a separate thread. Student threads will alternate between programming for a period of time and seeking help from the TA. If the TA is
available, they will obtain help. Otherwise, they will either sit in a chair in the waiting area or, if no chairs are available, will resume programming and seek help at a later time.
When a student arrives and finds an empty chair, the student must notify the coordinator using a semaphore. When the TA is free (initially and after helping a student)
, the TA must notify the coordinator using a semaphore. Also, waiting students and TAs must be woken up by the coordinator using separate semaphores. For details on
how to use pthreads, synchronization primitives mutex and semaphores see the book.
To simulate programming and getting help in students threads, and the TA providing help to a student in the TA thread, the appropriate threads should sleep (by invoking sleep()) for a random of time (up to three seconds).
The total number of students, the number of TAs, the number of chairs, and the number of times a student seeks a TAs help are passed as command line arguments
as shown below (csmc is then ame of the executable):
csmc #students#TAs#chairs#help
csmc 10 3 4 5
Once a student thread takes the required number of help from the TAs, it should terminate. Once all the student threads are terminated, the TA threads, the coordinator thread, and finally the main program should be terminated.
Output
Your program must output the following at the appropriate times:
Student [#] takes a seat.
Waiting students = [# of students waiting]
Student [#] found no empty chair will try again later
TA [#] helping student for [#] seconds.
Waiting students = [# of students waiting]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
