Search
 
SCRIPT & CODE EXAMPLE
 

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

PREVIOUS NEXT
Code Example
Python :: odoo 12 python version 
Python :: gitlab ci deploy key 
Python :: Permission error 
Python :: python list len 
Python :: install python 3 ubuntu 16.04 
Python :: HTML default value fo radio button input type based on python variable 
Python :: plot bar 
Python :: if space bar pressed pygame 
Python :: pandas combine bool columns 
Python :: tdlib python 
Python :: python json string indices must be integersAdd Answer 
Python :: knn.score sklearn 
Python :: ring Search List Item 
Python :: print all gpu available tensor 
Python :: z3 symbolic expressions cannot be cast to concrete boolean values 
Python :: ring Desktop, WebAssembly and Mobile create an application to ask the user about his/her name. 
Python :: matplotlib plot dpi - change format to svg 
Python :: module not imorting idle 
Python :: python 2nd order ode 
Python :: pandas count zeros in column 
Python :: trello class 
Python :: python class overwrite length method 
Python :: KMeans 
Python :: modeltranslation 
Python :: self.tk.call( _tkinter.TclError: unknown option "-relwdth" 
Python :: how to take matrix input in python 
Python :: TypeError: get() takes 1 positional argument but 2 were given 
Python :: python execute echo to file 
Python :: pandas iloc range 
Python :: 198727191002 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =