Computers and Technology

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!

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 10:20, chonawilson4
Suppose there is a relation r(a, b, c) with a b+-tree index with search keys (a, b).1. what is the worst-case cost of finding records satisfying 10 < a < 50 using this index, in terms of the number of records n1, retrieved and the height h of the tree? 2. what is the worst-case cost of finding records satisfying 10 < a < 50 and 5 < b < 10 using this index, in terms of the number of records n2 that satisfy this selection, as well as n1 and h defined above? 3. under what conditions on n1 and n2, would the index be an efficient way of finding records satisfying the condition from part (2)?
Answers: 1
image
Computers and Technology, 24.06.2019 12:30, stephanieanaya7
Why does the pc send out a broadcast arp prior
Answers: 1
image
Computers and Technology, 25.06.2019 00:40, lexieprochaskaaa
Roger ginde is developing a program in supply chain management certification for managers. ginde has listed a number of activities that must be completed before a training program of this nature could be conducted. the activities, immediate predecessors, and times appear in the accompanying table: activity immediate predecessor(s) time (days) a -− 44b -− 55 c -− 11 d b 1010 e a, d 55 f c 55 g e, f 1010 calculate the slack time. show the details.
Answers: 2
image
Computers and Technology, 26.06.2019 05:00, tiffcarina69
It's expected that, by 2016, there will be almost global network connections. twelve billion nineteen billion three trillion none of the above
Answers: 1
Do you know the correct answer?
Sleeping Teacher Problem

The computer science department runs a mentoring center to hel...

Questions in other subjects:

Konu
Mathematics, 17.10.2020 14:01