文件名称:BarberAndCustomer
介绍说明--下载内容均来自于网络,请自行研究使用
1)用C语言或C++语言编程实现P、V原语并用P、V原语描述如下生产者-消费者问题:
有一个理发师,一把理发椅和n把提供给等候理发的顾客座的椅子。如果没有顾客,则理发师便在理发椅子上睡觉;当第一个顾客到来时,必须唤醒该理发师进行理发;如果理发师正在理发时又有顾客到来,则如果有空椅子可坐,他就坐下来等待,如果没有空椅子,他就离开理发店。
为理发师和顾客各编一段程序描述他们的行为,要求不能带有竞争条件,试用P、V操作实现。
(2)分析
此题可看作是n个生产者和1个消费者问题。
顾客作为生产者,每到来一个就使计数器rc增加1,以便让理发师理发(相当于消费)至最后一个顾客(相当于产品)。并且,第1个到来的顾客应负责唤醒理发师;如果不是第1个到达的顾客,则在有空椅子的情况下坐下等待,否则离开理发店(该消息可由计数器rc获得)。
有一个理发师,一把理发椅和n把提供给等候理发的顾客座的椅子。如果没有顾客,则理发师便在理发椅子上睡觉;当第一个顾客到来时,必须唤醒该理发师进行理发;如果理发师正在理发时又有顾客到来,则如果有空椅子可坐,他就坐下来等待,如果没有空椅子,他就离开理发店。
为理发师和顾客各编一段程序描述他们的行为,要求不能带有竞争条件,试用P、V操作实现。
(2)分析
此题可看作是n个生产者和1个消费者问题。
顾客作为生产者,每到来一个就使计数器rc增加1,以便让理发师理发(相当于消费)至最后一个顾客(相当于产品)。并且,第1个到来的顾客应负责唤醒理发师;如果不是第1个到达的顾客,则在有空椅子的情况下坐下等待,否则离开理发店(该消息可由计数器rc获得)。
(系统自动生成,下载前可以参看下载内容)
下载文件列表
BarberAndCustomer\Barber\barber.cpp
.................\......\Barber.vcproj
.................\......\Barber.vcproj.MICROSOF-5AF945.Administrator.user
.................\......\Debug\Barber.exe.embed.manifest
.................\......\.....\Barber.exe.embed.manifest.res
.................\......\.....\Barber.exe.intermediate.manifest
.................\......\.....\barber.obj
.................\......\.....\BuildLog.htm
.................\......\.....\mt.dep
.................\......\.....\vc90.idb
.................\......\.....\vc90.pdb
.................\BarberAndCustomer.ncb
.................\BarberAndCustomer.sln
.................\BarberAndCustomer.suo
.................\Customer\Customer.cpp
.................\........\Customer.vcproj
.................\........\Customer.vcproj.MICROSOF-5AF945.Administrator.user
.................\........\Debug\BuildLog.htm
.................\........\.....\Customer.exe.embed.manifest
.................\........\.....\Customer.exe.embed.manifest.res
.................\........\.....\Customer.exe.intermediate.manifest
.................\........\.....\Customer.obj
.................\........\.....\mt.dep
.................\........\.....\vc90.idb
.................\........\.....\vc90.pdb
.................\Debug\Barber.exe
.................\.....\Barber.ilk
.................\.....\Barber.pdb
.................\.....\Customer.exe
.................\.....\Customer.ilk
.................\.....\Customer.pdb
.................\.....\QueueCustomer.dll
.................\.....\QueueCustomer.exp
.................\.....\QueueCustomer.ilk
.................\.....\QueueCustomer.lib
.................\.....\QueueCustomer.pdb
.................\Instruction.txt
.................\QueueCustomer\Debug\BuildLog.htm
.................\.............\.....\mt.dep
.................\.............\.....\QueueCustomer.dll.embed.manifest
.................\.............\.....\QueueCustomer.dll.embed.manifest.res
.................\.............\.....\QueueCustomer.dll.intermediate.manifest
.................\.............\.....\QueueCustomer.obj
.................\.............\.....\vc90.idb
.................\.............\.....\vc90.pdb
.................\.............\QueueCustomer.cpp
.................\.............\QueueCustomer.h
.................\.............\QueueCustomer.vcproj
.................\.............\QueueCustomer.vcproj.MICROSOF-5AF945.Administrator.user
.................\Barber\Debug
.................\Customer\Debug
.................\QueueCustomer\Debug
.................\Barber
.................\Customer
.................\Debug
.................\QueueCustomer
BarberAndCustomer
.................\......\Barber.vcproj
.................\......\Barber.vcproj.MICROSOF-5AF945.Administrator.user
.................\......\Debug\Barber.exe.embed.manifest
.................\......\.....\Barber.exe.embed.manifest.res
.................\......\.....\Barber.exe.intermediate.manifest
.................\......\.....\barber.obj
.................\......\.....\BuildLog.htm
.................\......\.....\mt.dep
.................\......\.....\vc90.idb
.................\......\.....\vc90.pdb
.................\BarberAndCustomer.ncb
.................\BarberAndCustomer.sln
.................\BarberAndCustomer.suo
.................\Customer\Customer.cpp
.................\........\Customer.vcproj
.................\........\Customer.vcproj.MICROSOF-5AF945.Administrator.user
.................\........\Debug\BuildLog.htm
.................\........\.....\Customer.exe.embed.manifest
.................\........\.....\Customer.exe.embed.manifest.res
.................\........\.....\Customer.exe.intermediate.manifest
.................\........\.....\Customer.obj
.................\........\.....\mt.dep
.................\........\.....\vc90.idb
.................\........\.....\vc90.pdb
.................\Debug\Barber.exe
.................\.....\Barber.ilk
.................\.....\Barber.pdb
.................\.....\Customer.exe
.................\.....\Customer.ilk
.................\.....\Customer.pdb
.................\.....\QueueCustomer.dll
.................\.....\QueueCustomer.exp
.................\.....\QueueCustomer.ilk
.................\.....\QueueCustomer.lib
.................\.....\QueueCustomer.pdb
.................\Instruction.txt
.................\QueueCustomer\Debug\BuildLog.htm
.................\.............\.....\mt.dep
.................\.............\.....\QueueCustomer.dll.embed.manifest
.................\.............\.....\QueueCustomer.dll.embed.manifest.res
.................\.............\.....\QueueCustomer.dll.intermediate.manifest
.................\.............\.....\QueueCustomer.obj
.................\.............\.....\vc90.idb
.................\.............\.....\vc90.pdb
.................\.............\QueueCustomer.cpp
.................\.............\QueueCustomer.h
.................\.............\QueueCustomer.vcproj
.................\.............\QueueCustomer.vcproj.MICROSOF-5AF945.Administrator.user
.................\Barber\Debug
.................\Customer\Debug
.................\QueueCustomer\Debug
.................\Barber
.................\Customer
.................\Debug
.................\QueueCustomer
BarberAndCustomer