操作系统实验报告barber实验.docxVIP

  • 39
  • 0
  • 约2.38万字
  • 约 25页
  • 2017-12-10 发布于河南
  • 举报
操作系统实验报告barber实验

操作系统实验报告实验题目:barber实验实验目的进一步研究和实践操作系统中关于并发进程同步与互斥操作的一些经典问题的解法,加深对于非对称性互斥问题有关概念的理解。观察和体验非对称性互斥问题的并发控制方法。实验原理理发店有一个出口一个入口,没顾客的时候理发师在打瞌睡,有顾客的时候理发师在椅子上等待的顾客中选出顾客来理发,顾客进店就坐在椅子上等待(也有做沙发),没有椅子坐的人就站着排队(也有的省去站着排队的环节,以下就是),连站着排队的位置也没有的时候就直接离开。它的实质是生产者和消费者的问题。实验代码编写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());}}}编写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());}}}}编写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 int[] customerStandQ;//the queue to hold the customers on the standing areaprivate int[] customerChairQ;//the queue to hold the customers on Barber Chairsprivate int[] customerPayQ;//the queue to hold the customers waiting for paying.private int[] customerReady; //cutomerReady[i] = 1, customer i is ready for barber 1private int[] finishedCustomerQ; //the array to

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档