Assignment-4 Operating Systems-Ii: System Model Overview
Assignment-4 Operating Systems-Ii: System Model Overview
OPERATING SYSTEMS-II
Amitanshu Sahoo
ME18BTECH11050
STRUCTURE USED
There is only one structure that is used in the code to pass the parameters related to a single customer
while creating a thread. The structure is hence named “customer”. It takes two arguments which are.
• The process/customer ID
• The eating time of the customer in the restaurant
The decision for eating time can also be taken while the person is eating inside the “restaurant”
function. However, this implementation is merely cosmetic in nature and does produce any different
result from the implementation used here.
FUNCTION DESCRIPTION
There are three functions that are used in the code: -
I. restaurant function – This is the function which simulates the Korean restaurant
problem and is described in detail in the next section.
II. insertion sort function – The insertion sort function is used to sort the log file arrays as
described below in order of the time stamps at which they occur.
III. merge function – It is used to merge the log file arrays after they are sorted to obtain a
master log file which in turn is printed to the output file.
RESTAURANT FUNCTION
The restaurant function is function which implements the Korean restaurant problem. It uses two
binary semaphores “mutex” and “block”. The mutex lock is initialized such that it is unlocked, and
the block lock is locked at initialization. The variables “eating” and “waiting” store the number of
people eating at the table and the number of people waiting to be admitted to the table, respectively.
The pseudocode describing the algorithm is given as follows: -
Void *restaurant (arguments in the form of structure) {
The values of the passed structure are stored in a structure variable named “person”.
The gettimeofday function is called to store the request time values in timeval struct instance “req”.
Must_wait = true.
All the process now waits at wait(&block) statement for signal to get into critical section.
The gettimeofday function is called to store the access time values in timeval struct instance “acc”.
Else {
The must_wait variable (which signifies the formation of group) is set to true according to the condition
if there is someone waiting and the number of at the table is equal to X.
The gettimeofday function is called to store the access time values in timeval struct instance “acc”.
The gettimeofday function is called to store the exit time values in timeval struct instance “ext”.
The must_wait variable (which signifies the formation of group) is set to true according to the condition
if there is someone waiting and the number of at the table is equal to X.
The block semaphore is signalled k times to allow the waiting processes to acquire the table.
When the table has vacant seats, the incoming processes execute the first else statement and proceed
to the critical section. When all the seats are taken, and a group is formed the incoming processes are
blocked by the block semaphore.
If people start leaving from the table when the group is already formed, the waiting processes are not
allowed into the critical section until the last process leaves the table and signal the waiting processes.
In case the number of waiting processes is greater than X it only signal X processes to come to the
critical section and again form a group. If the number of waiting processes is less than X, then it
simply allows them into the critical section and no group is formed.
• The values for the graphs have been averaged over 5 readings at each abscissa point.
• lambda = 1.5, gamma = 0.75, r = 2.
• As the number of threads are increasing the average waiting time is also increasing
(keeping the number of participants on the table constant at 4). This is because as the
number of threads are increasing there is more chance of a situation where more
threads are waiting.
AVERAGE WAITING TIME VS X
• Average waiting time is decreasing if the number of participants on the table are
increasing keeping the total number of customers constant. This is to be expected
because if we increase X, we are essentially letting more people into the critical
section at the same time. Hence the amount of time a single process waits for
decreases.
NOTE :- All the times displayed in the output log file are with respect to the start time as
stored by the timeval struct instance “start” at the starting of the execution of main().