subject

The computer science department runs a mentoring center to 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 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 from the teacher. if the teacher is available, they will obtain . otherwise, they will either sit in a chair in the waiting area or, if no chairs are available, will resume programming and seek 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 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 to a student in the teacher thread, the appropriate threads should sleep (by invoking 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 are passed as command line arguments as shown below (csmc is the name of the executable):

csmc #students #teachers #chairs #

csmc 10 3 4 5

once a student thread takes the required number of 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[#] 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 would be greatly appreciated!

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:30, DestinyK8033
Why would a programmer use the logical operator and in an if statement? a: when an action is to be taken that requires both conditions to be falseb: when an action is to be taken that requires both conditions to be truec: when an action is to be taken that requires the first condition to be falsed: when an action is to be taken that requires the second condition to be truei took the test and the answer is b.
Answers: 3
image
Computers and Technology, 24.06.2019 14:00, maddi0132
In the microsoft® access® and microsoft excel® programs, the ribbon contains tabs that are divided into with like tools in them. parts groups containers bunches
Answers: 1
image
Computers and Technology, 24.06.2019 16:50, Laylahlettiere
Develop the program incrementally: a) start by reading and displaying each line of the input file to make sure you are reading the data set correctly. b) use the split string method to extract information from each line into a list. print the list to prove that this step is working correctly. d) convert the exam scores to type int and calculate the student’s average. display those items to prove this step is working correctly. e) create a tuple containing the six items for each student (name, exam scores, exam mean). display the tuples to prove this step is working correctly. (optionally, you may want to have the exam scores in a list so your tuple is (name, scores_list, f) append each tuple to a list. display the list to prove this step is working correctly. g) use the sort list method to re-order the tuples in the list. display the list to prove this step is working correctly. h) use a for statement to display the contents of the list as a table (with appropriate formatting). i) use a for statement to calculate the average of all scores on exam #1, then display the results. note that you could have calculated this average within the first loop, but we are explicitly requiring you to do this calculation by looping though your list of tuples. j) add the logic to calculate the average of all scores on exam #2, then display the results.
Answers: 2
image
Computers and Technology, 24.06.2019 17:40, xinkyx616
Pseudocode pld #6, pg. 117 start// declarations// number numbertoguess// number myguess; numbertoguess = 92// while myguess ! = numbertoguess// output " guess an integer number between 1 and 100"// input myguess// if (myguess == numbertoguess)// output "you guessed the correct number"// else// output "the number you guessed was incorrect. try again! "// end if// end while// output " for playing the guessing game. have a great day! "// stop
Answers: 3
You know the right answer?
The computer science department runs a mentoring center to undergraduate students with their progra...

Questions in other subjects:

Konu
Mathematics, 29.05.2021 16:40