A university computer science department has a teaching assistant (TA) who helps undergraduate students with their programming assignments. The TA’s 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, the TA sits at the desk and takes a nap. If a student arrives and finds the TA sleeping, the student must awaken the TA 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 come back at a later time. Using threads, implement a solution that coordinates the activities of the TA and the students. Details for this assignment are provided below. The Students and the TA Using threads (Section 4.4), begin by creating n students. Each will run as a separate thread. The TA will run as a separate thread as well. Student threads will seek help from the TA. If the TA is available, they will obtain help. Otherwise, they will either sit on a chair in the hallway or, if no chairs are available, will seek help at a later time (random period of time). If a student arrives and notices that the TA is sleeping, the student must notify the TA using a semaphore. 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. If no students are present, the TA may return to napping. Simulating the TA providing help to a student is to have the appropriate threads sleep for a random period of time. Use the below functions and implement the program in C language. Main function:: int main(int argc, char *argv[]) { // Initialize your variables // Create TA thread sleep(1); for(i=0;i #include #define SLEEP 0 #define WAKEUP 1 int semaphore; int MAX, TA, TTL; int ENDOFPROGRAM; int curstudent; int waitinglist; Flowchart - main():: MAIN START Get user input (Number of students) Create TA thread (TA is sleeping)  Create student threads MAIN END

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

A university computer science department has a teaching assistant (TA) who helps undergraduate students with their programming assignments. The TA’s 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, the TA sits at the desk and takes a nap. If a student arrives and finds the TA sleeping, the student must awaken the TA 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 come back at a later time. Using threads, implement a solution that coordinates the activities of the TA and the students.

Details for this assignment are provided below.

The Students and the TA Using threads (Section 4.4), begin by creating n students. Each will run as a separate thread. The TA will run as a separate thread as well. Student threads will seek help from the TA. If the TA is available, they will obtain help. Otherwise, they will either sit on a chair in the hallway or, if no chairs are available, will seek help at a later time (random period of time). If a student arrives and notices that the TA is sleeping, the student must notify the TA using a semaphore. 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. If no students are present, the TA may return to napping. Simulating the TA providing help to a student is to have the appropriate threads sleep for a random period of time.

Use the below functions and implement the program in C language.

Main function::

int main(int argc, char *argv[]) { // Initialize your variables

// Create TA thread

sleep(1);

for(i=0;i<MAX;i++){

sleep(1);

// Create students threads

}

for(j=0;j<MAX;j++){

// Join all the threads

}

}

Semaphore wait() function::

void wait(int sema, int param)

{

while(sema == 0) {}

if(param == 0)

printf("[SEMAPHORE] TA gets the lock!\n");

else

printf("[SEMAPHORE] Student %d gets the lock!\n",param);

sema--;

}

Semaphore signal() function::

void signal(int sema, int param) {

if(param == 0)

printf("[SEMAPHORE] TA releases the lock!\n"); else printf("[SEMAPHORE] Student %d releases the lock!\n",param);

sema++;

}

Thread sleepingta() function::

void *sleepingta(void *param) {

// Wait & get the lock

printf("[TA THREAD] TA is in the office.\n");

// Release the lock

while(ENDOFPROGRAM)

{

// Add your logic

}

// End thread }

Thread student() function::

void *student(void *param) {

// Wait & get the lock

printf("[STUDENT THREAD] Student %d is coming!\n",*(int*)param);

// Add your logic

// Release the lock

// End thread

}

Variables::

#include<pthread.h>

#include<stdio.h>

#define SLEEP 0

#define WAKEUP 1

int semaphore;

int MAX, TA, TTL;

int ENDOFPROGRAM;

int curstudent;

int waitinglist;

Flowchart - main()::

MAIN START

Get user input (Number of students)

Create TA thread (TA is sleeping) 

Create student threads

MAIN END

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 11 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education