Evaluation project to obtain a grade for the subject Operating Systems (IEC584) in the Computer Engineering course at the Federal University of Amazonas.
Recruit Zero's Barbershop" is a simulation of the "sleeping barber" problem, set in a barbershop located inside an American fort on the outskirts of San Francisco. The aim is to get the barber, known as Recruit Zero, to serve customers according to specific criteria. This implementation uses threads and semaphores (pthreads) and offers a variation on the problem often found in computer science textbooks.
The system is made up of several elements:
-
Sergeant Tainha: A sleepy sergeant who periodically tries to add a new customer to the barbershop's queue of chairs, as long as there is room available. The time between his naps is variable, set by the user.
-
The Barbershop: Customers share 20 chairs, distributed in three FIFO queues, one for officers, another for sergeants and the third for corporals. Each barber serves one customer at a time.
-
Recruit Zero - The Barber: Responsible for cutting hair, the service time varies according to the customer's rank: officers (4-6 seconds), sergeants (2-4 seconds) and corporals (1-3 seconds). Priority for service follows the order: officers, sergeants and corporals.
-
Lieutenant Escovinha: Responsible for providing performance reports. Every 3 seconds, the Escovinha checks the state of the barbershop and, at the end of each day, draws up a report with various pieces of information, such as chair occupancy, average queue length, average service time and average waiting time by category, number of services and total customers by category.
The data is randomly generated in the format: <category><time of service>
, where the category can be 1 (officer), 2 (sergeant), 3 (corporal) or 0 (pause, indicating that the queue is empty).
The execution ends when Sergeant Mullet finds no more customers waiting outside the barbershop in three sequential attempts. At this point, the sergeant can go home, but the barber continues to serve customers inside the barbershop.
The repository includes implementations for three different scenarios:
- Case A: Recruit Zero attends to all three queues, with priority given to officers, followed by sergeants and corporals.
- Case B: Recruit Zero has hired Dentinho, another barber, to help, maintaining the priority of service categories.
- Case C: The barbershop has hired two other barbers, Dentinho and Otto, each dedicated exclusively to one queue. However, if the queue corresponding to one of the barbers is empty, the corresponding barber can serve customers from another queue, in order of priority.
- Source code for the implementations.
- Detailed documentation for running and exploring the scenarios.
- Reports generated by Lieutenant Escovinha, evaluating the barbershop's performance in each case.
Follow the instructions below to compile and run the project:
-
Open the terminal or command prompt.
-
Make sure you are in the root directory of the project.
-
Run the following command to build the project:
make build
This will compile the source code and generate the JAR file or other artifacts, depending on the project configuration.
-
Open the terminal or command prompt.
-
Run the following command to start the project:
make run ARGS="--barbershopCase C --tainhaSleepingTime 5"
-
Make sure you have an input file in the correct format.
-
Open the terminal or command prompt.
-
Run the following command to start the project with the customized input file:
make run-with-input INPUT_FILE=file.txt ARGS="--barbershopCase C --tainhaSleepingTime 5"
Make sure you replace file.txt
with the name of the desired input file.
To remove the generated artifacts and clean up the project, run the following command:
make clean
Contributions are welcome to improve the implementation and add new scenarios. Feel free to create a fork of this repository and send pull requests.
Andevaldo Vitório
- E-mail: [email protected]