Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will use POSIX mutex locks and semaphores to implement a solution that coordinates the activities of a TA and students as
In this assignment, you will use POSIX mutex locks and semaphores to implement a solution
that coordinates the activities of a TA and students as described below.
A university computer science department has a teaching assistant TA that holds office hours
where they provide help to students with their programming assignments. The TAs office is rather
small, and only has room for one desk with a chair and a computer. There are three chairs outside
the office where students may sit and wait if the TA is currently helping another student. If there
are no available chairs in the waiting area, the student leaves and shows up at a later time. When
the TA has finished helping a student, she goes outside to the waiting area to see if there are
waiting students. If so she takes the next student and begins to help them. If there are no waiting
students, she returns to her chair in he office and takes a nap. If a student shows up and sees the
TA sleeping, the student wakes her up
Using POSIX mutex locks and sempahores, design a solution to coordinate the activities of the
TA and students. A simple solution can use one mutex lock and two semaphores: i the mutex
lock for controlling access to the chairs. You will need to keep track of the number of waiting
students and that variable is a shared variable. ii a counting semaphore for waiting students. ii
a binary semaphore for represesnting whether the TA is available or not.
Students and the TA: Using Pthreads, begin by creating N students where each student runs
as a separate thread. In addition, the TA will also run as a separate thread. Student threads will
alternate between programming for a period of time, and then seeking help from the TA If the TA
is available, they will obtain help or will sit in a hallway while waiting their turn with the TA If
there are no chairs available, the student will resume programming on their own, and seek help at
a later time. If a student arrives and notices the TA is sleeping, they must notify the TA using the
appropriate semaphore.
If the TA is helping a student, upon finishing they must check if there are waiting students in
the hallway. If so they must help them as well. They will notify a waiting student by using the
appropriate semaphore. If there are no waiting students, the TA can take a nap.
Programming and Helping: Perhaps the best way of simulating the students programming
and the TA helping a student is for them to sleep for a random period of time using the sleep
function, and displaying a message on what they are doing, egTA is helping student number
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