subject

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 teacher’s 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!

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:30
This first part of the film shows the early history of motion pictures. how accurate do you think the portrayal of the early motion picture industry is? why? is historical accuracy important in films and theatre productions? explain. in the scene where don is going to the party (starting at time code 14: 51), we see a street scene as he first rides with cosmo and then with kathy. what aspects did the filmmaker include to make the scene look and feel like don, cosmo, and kathy are riding in a car on a street? think about elements such as scenery, sound, props, lighting, and so on. a "talkie" picture is shown starting around time code 21: 15. how does the audience in the film react to the "talkie"? what influence do audiences have on film and theatre performances? how do film and theatre actors influence audiences? in the musical scene with cosmo (starting at time code 27: 00), how does the actor use props? what is the result? do you think the use of props effectively fulfilled the artistic vision for this musical number? why or why not?
Answers: 1
question
Computers and Technology, 22.06.2019 20:00
The blank button automatically displays next to the data when you select a range of numeric data which is an available option for creating a chart
Answers: 3
question
Computers and Technology, 22.06.2019 21:30
The salespeople at hyperactive media sales all use laptop computers so they can take data with them on the road. you are a salesperson for superduper lightspeed computers talking to hyperactive media sales about upgrading the laptops to windows 10. explain how network location awareness in windows 10 would make the laptops more secure.
Answers: 3
question
Computers and Technology, 23.06.2019 21:00
Which task uses a simple parameter?
Answers: 1
You know the right answer?
Sleeping Teacher Problem

The computer science department runs a mentoring center to hel...
Questions
Questions on the website: 13722361