Your task is to implement a solution that coordinates the activities of the TA and the students using POSIX threads, mutex locks, and semaphores. Details for this assignment are provided below.

A university computer science department has a teaching assistant (TA) who helps undergraduate students with their programming assignments during regular office hours. The TA's office is rather small and has room for only one desk with a chair and computer. There are three chairs in the hallway outside the office where students can sit and wait if the TA is currently helping another student. When there are no students who need help during office hours, the TA sits at the desk and waits. If a student arrives during office hours, the student must awaken the TA to ask for help. If a student comes and finds the TA currently helping another student, the student sits on one of the chairs in the hallway and waits. If no chairs are available, the student will come back at a later time.

Using Pthreads begin by creating n students. Each will run as a separate thread. The TA will run as an independent thread as well. Student threads will alternate between programming for a period and be seeking help from the TA. If the TA is available, they will obtain help. Otherwise, they will either sit in a chair in the hallway or, if no chairs are available, will hang out a little bit and seek help at a later time. If a student arrives and notices that the TA is waiting, the student must notify the TA using a semaphore. If students are waiting for help in the hallway, the TA must help each of these students in turn.

This solution should adhere to the following constraints:

1.At least 5 students;

2.Each student needs to seek help successfully three times; 3. Each student must print:

a.The thread ID,
b.The programming/hang out duration in seconds;
c.A message shows the student is receiving help;

4. Writers must print:

a.The duration of meeting a student in seconds;
b.The number of waiting students present when helping a student.

Hint:

Perhaps the best option for simulating students programmingas well as the TA providing help to a studentis to have the appropriate threads sleep for a random period. Instead of usleep()accepts argument in microseconds, sleep() accepts argument in seconds. A sample code is provided in student_ta.c. However, you are free to implement the solution using any combinations of mutexes and semaphores as long as the solution follows the description above.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.