OS - Theory - DA2 Question
OS - Theory - DA2 Question
Digital Assignment – 2
1. Consider the following classical synchronization problem called the barbershop problem. A
barbershop consists of a room with N chairs. If a customer enters the barbershop and all chairs
are occupied, then the customer leaves the shop. If the barber is busy, but chairs are available,
then the customer sits in one of the free chairs and awaits his turn. The barber moves onto
the next waiting seated customer after he finishes one hair cut. If there are no customers to
be served, the barber goes to sleep. If the barber is asleep when a customer arrives, the
customer wakes up the barber to give him a hair cut. A waiting customer vacates his chair
after his hair cut completes. Your goal is to write the pseudocode for the customer and barber
threads below with suitable synchronization. You must use only semaphores to solve this
problem. Use the standard notation of invoking up/down functions on a semaphore variable.
Write the pseudocode and implement using C program. (2 Marks)
2. Multiple people are entering and exiting a room that has a light switch. You are writing a
computer program to model the people in this situation as threads in an application. You must
fill in the functions onEnter() and onExit() that are invoked by a thread/person when the
person enters and exits a room respectively. We require that the first person entering a room
must turn on the light switch by invoking the function turnOnSwitch(), while the last person
leaving the room must turn off the switch by invoking turnOffSwitch(). You must invoke these
functions suitably in your code below. You may use any synchronization primitives of your
choice to achieve this desired goal. You may also use any variables required in your solution,
which are shared across all threads/persons.
(a) Variables and initial values
(b) Code onEnter() to be run by thread/person entering
(c) Code onExit() to be run by thread/person exiting
Write the pseudocode and implement using C program. (2 Marks)
*Tab Completion:
Implement tab completion for commands and file paths. When a user types part of a
command or file path and presses the tab key, the shell should suggest completions based on
existing commands or files in the system.
(4 Marks)