文件名称:barber
介绍说明--下载内容均来自于网络,请自行研究使用
睡眠理发师问题C++解法,使用信号量,理发座位数可选,理发师只有一个-Using semaphore to solve barbers problem,there’s one barber,infinite customer,and a few waiting position,the number of waiting position is depend on the user.
3 semaphores are involved in the program: m_h,barbers,customers.Barbers is for the hair cutting process,customers
Is for each customer’s arriving process,m_h is for a waiting position counter.There’re 2 more handles:threada,threadb as thread handle.
Whenever a customer arrives,program prints: No.xxx customer is coming.If there exists any empty waiting position,the customer turn into a waiting situation,if not,program prints: No room for No.xxx customer,it s leaving.When the barber finishes a haircut,the barber thread prints: Done!Barber has cut a customer.....,meanwhile,the customer thread also prints: No.xxx customer has finished and leaving.
With a While(1){} structure,the barber thread would never stop .The customer thread has no While() structure but the main function will continually and ramdomly create a customer
3 semaphores are involved in the program: m_h,barbers,customers.Barbers is for the hair cutting process,customers
Is for each customer’s arriving process,m_h is for a waiting position counter.There’re 2 more handles:threada,threadb as thread handle.
Whenever a customer arrives,program prints: No.xxx customer is coming.If there exists any empty waiting position,the customer turn into a waiting situation,if not,program prints: No room for No.xxx customer,it s leaving.When the barber finishes a haircut,the barber thread prints: Done!Barber has cut a customer.....,meanwhile,the customer thread also prints: No.xxx customer has finished and leaving.
With a While(1){} structure,the barber thread would never stop .The customer thread has no While() structure but the main function will continually and ramdomly create a customer
(系统自动生成,下载前可以参看下载内容)
下载文件列表
barber.cpp