⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customer.java

📁 这是操作系统的程序设计
💻 JAVA
字号:
/**
 * 消费者
 *
 */
public class Customer implements Runnable{
	private Semaphore mutex,full,empty;
	private Buffer buf;
	String name;
	public Customer(String name,Semaphore mutex,Semaphore full,Semaphore empty,Buffer buf){
		this.mutex  = mutex;
		this.full  = full;
		this.empty = empty;
		this.buf = buf;
		this.name = name;
	}
	public void run(){
		while(true){
			full.p();
			mutex.p();
			System.out.println(name+" gets a  product from "+buf.nextFullIndex);
			buf.nextFullIndex = (buf.nextFullIndex+1)%buf.size;
			mutex.v();
			empty.v();	
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {				
				e.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -