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

📄 producer.java

📁 这是操作系统的程序设计
💻 JAVA
字号:
/**
 * 生产者
 *
 */
public class Producer implements Runnable{
	private Semaphore mutex,full,empty;
	private Buffer buf;
	String name;
	public Producer(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){
			empty.p();
			mutex.p();
			System.out.println(name+" inserts a new product into "+buf.nextEmptyIndex);
			buf.nextEmptyIndex = (buf.nextEmptyIndex+1)%buf.size;
			mutex.v();
			full.v();	
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {				
				e.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

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