Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Our Department has a teaching assistant who helps undergraduate students with their programming assignments during regular office hours. The TAs office is rather small and

Our Department has a teaching assistant who helps undergraduate students with their programming assignments during regular office hours. The TAs office is rather small and has room for only one desk with a chair and computer. There are three chairs in the hallway outside the office where students can sit and wait if the TA is currently helping another student. When there are no students who need help during office hours, the TA sits at the desk and takes a nap. If a student arrives during the office hours and finds the TA sleeping, the student must awaken the TA (using a semaphore) to ask for help, if a student arrives and finds the TA currently helping another student, the student sits on one of the chairs in the hallway and waits. If no chairs are available, the student will go back to programming and come back at a later time. When the TA finishes helping a student, the TA must check to see if there are students waiting for help in the hallway. If so, the TA must help each of these students in turn. Using Pthreads, begin by creating 10 students. Each will run as a separate thread. The TA will run as a separate thread as well. Students thread will alternate between programming for a period of time and seeking help from the TA. To simulate students programming as well as the TA providing help to a student is to have the appropriate thread to sleep for a random period of time. Each student thread should print its state (programming, waiting to get help, getting help, TA not available back to programing) along with its threadID. Similarly, the TA should print its state (helping, getting the next student, napping). Program in C

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions