Skip to content

This repository contains an implementation of the "Recruit Zero Barbershop" problem, a scenario based on threads and semaphores (pthreads) set in the barbershop comfortably installed inside an American fort. The implementation challenges the barber, known as Recruit Zero, to serve all customers according to strict criteria. Resources

Notifications You must be signed in to change notification settings

andel-vitorio/recruta-zero-babershop

Repository files navigation

Recruit Zero's Barbershop

Evaluation project to obtain a grade for the subject Operating Systems (IEC584) in the Computer Engineering course at the Federal University of Amazonas.

Description

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.

How it works

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.

Data Entry

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).

End of Execution

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.

Results

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.

Repository content

  • 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.

How to Run

Follow the instructions below to compile and run the project:

Compiling the Project

  1. Open the terminal or command prompt.

  2. Make sure you are in the root directory of the project.

  3. 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.

Running the Project

  1. Open the terminal or command prompt.

  2. Run the following command to start the project:

    make run ARGS="--barbershopCase C --tainhaSleepingTime 5"

Running the Project with a Custom Input File

  1. Make sure you have an input file in the correct format.

  2. Open the terminal or command prompt.

  3. 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.

Cleanup

To remove the generated artifacts and clean up the project, run the following command:

make clean

Contribution

Contributions are welcome to improve the implementation and add new scenarios. Feel free to create a fork of this repository and send pull requests.

Author

Andevaldo Vitório

About

This repository contains an implementation of the "Recruit Zero Barbershop" problem, a scenario based on threads and semaphores (pthreads) set in the barbershop comfortably installed inside an American fort. The implementation challenges the barber, known as Recruit Zero, to serve all customers according to strict criteria. Resources

Topics

Resources

Stars

Watchers

Forks