Question
Sleeping Teacher Problem The computer science department runs a mentoring center to help undergraduate students with their programming assignments. The lab has a coordinator and
Sleeping Teacher Problem
The computer science department runs a mentoring center to help undergraduate students with their programming assignments. The lab has a coordinator and several teachers to assist the students.The waiting area of the center has several chairs. Initially, all the chairs are empty, the coordinator is waiting for students to arrive and all the teachers 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 tutoring. 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 teacher, if there is one, and assigns the student to the teacher. If all the teachers are busy assisting students, the coordinator waits for a teacher to get free and then assigns a waiting student to the teacher. A teacher 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, teachers, and the students. Some hints to implement this project are provided next.
Implementation Hints
Using Pthreads, begin by creating n students and m teachers 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 teacher. If the teacher 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 teacher is free (initially and after helping a student), the teacher must notify the coordinator using a semaphore. Also, waiting students and teachers must be woken up by the coordinator using separate semaphores.
To simulate students programming in students threads, and the teacher providing help to a student in the teacher 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 teachers, the number of chairs, and the number of times a student seeks a teachers help are passed as command line arguments as shown below (csmc is the name of the executable):
csmc #students #teachers #chairs #help
csmc 10 3 4 5
Once a student thread takes the required number of help from the teachers, it should terminate. Once all the student threads are terminated, the teacher 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
Teacher[#] helping student for [#] seconds. Waiting students = [# of students waiting]
Grading Policy
Name your program file as csmc.c/cpp
We need to implement a version of the sleeping barber problem in C++. Any help would be greatly appreciated!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started