Assume that you are asked to develop a simple multithread program that counts the number of people coming thru each of the four gates- A, B, C, D in a music concert hall in real time, and displays the number of remaining seats for each of those gates. The program should also display the total count of people in the hall now.
gcc asgn4.c -Wall -Werror -pthread
You are required to develop your own program using C with the following information:
The program needs to create separate threads such that:
Each thread is created with its own max capacity and gate name such as east, west, north, and south. (east, 5000), (west, 5000), (north, 1000), and (south, 15000)
East gate and west gate can allow to admit 5000 each, and close their gate when admittance is larger than or equal to 5000 (or less than equal to 0);
North gate can allow to admit 10000 each, and when admittance is larger than or equal to 10000 (or less than equal to 0);
South gate can allow to admit 15000 each, and when admittance is larger than or equal to 15000 (or less than equal to 0);
Upon each admittance the total count is updated;
Display your total count every 500th admittance with its corresponding gate name;
Script:
pthread_mutex_lock(&lock); ... Update total count; ... pthread_mutex_unlock(&lock);
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.