操作系统实验报告实验题目:barber 实验一、实验目的进一步研究和实践操作系统中关于并发进程同步与互斥操作的一些经典问题的解法,加深对于非对称性互斥问题有关概念的理解。观察和体验非对称性互斥问题的并发控制方法。二、实验原理理发店有一个出口一个入口,没顾客的时候理发师在打瞌睡,有顾客的时候理发师在椅子上等待的顾客中选出顾客来理发,顾客进店就坐在椅子上等待(也有做沙发),没有椅子坐的人就站着排队(也有的省去站着排队的环节,以下就是),连站着排队的位置也没有的时候就直接离开。它的实质是生产者和消费者的问题。三、实验代码1.编写 Customer.javapublic class Customer extends Thread{private BarberShopApplet tapplet;private BarberShop shop;private int cid;int delay= 2500;int status= 0;int cutFinish= 0;int barberID= 0;int paid= 0;public Customer(BarberShopApplet applet, BarberShop iq, int id){shop = iq;tapplet= applet;cid= id;}public void run(){try{status = 0;tapplet.mc.println(status, "c", cid);shop.sitSofa(tapplet, cid);sleep(delay);shop.sitBarberChair(tapplet, cid);shop.waitPay(tapplet, cid);} catch(InterruptedException e){System.err.println("Customer Exception " + e.toString());}}}2.编写 Barber.javapublic class Barber extends Thread{private BarberShop shop;private BarberShopApplet tapplet;private int pid;int delay= 2500;int status= 0;int customerID= 0;public Barber(BarberShopApplet applet, BarberShop iq, int id){shop= iq;tapplet = applet;pid = id;}public void run(){while(true){try{status = 0;tapplet.mc.println(status, "b", pid);sleep((int)(Math.random()*delay));shop.cutHair(tapplet, pid);sleep((int) (Math.random()*delay));shop.finishCut(tapplet, pid);} catch(InterruptedException e){System.err.println("Exception " + e.toString());}}}}3.编写 BarberShop.javaimport java.awt.*;public class BarberShop extends Canvas{private int chairSize= 3;private int sofaSize= 4;private int frameDelay= 3560;private int[] customerSofaQ;//the queue to hold the customers on the sofaprivate i...