Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

problème barbier semaphore python

I tested this program by creating a similar program which simulated the same scenario but without Threads. I used this test to help show the difference in time using threads and not using threads. 
Secondly I placed specific print statements at every branch to see what scenarios took place under certain circumstances and edited the global variables i.e. the number of barbers and seats available to see what events occured such as if there are more barbers than seats then some barbers will be constantly asleep and no customers should leave due to lack of seats and then vice versa where we minimised the barbers and increased the customers and saw the opposite where the barbers are constantly working and people are constantly leaving due to lack of seats. 
I also tested the threading.Event() by setting the flag to True and False and seeing how the program executed. When I started I planned on using locks and semaphores to synchronize The customers and barbers but the program got very code heavy therefore I opted to use a queue which handles synchronization easier. 
Some of the main problems I ran into were just small bugs including accidentally terminating all the customers when a single customer was served making the Queue equal to zero also I used a boolean to track whether the Barber was asleep and set it as a global variable by accident meaning that if one barber was awake it set all barbers as awake which is not the case; besides that I encountered a problem at the end of the program which makes it hang indefinitely, this is caused by a loop in the Barber Class which is infinite.
Source by github.com #
 
PREVIOUS NEXT
Tagged: #barbier #semaphore #python
ADD COMMENT
Topic
Name
7+9 =