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

📄 deadlock.txt

📁 关于死锁的银行家算法
💻 TXT
字号:
/*
 * Created on 2007-4-23
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author hulmous
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.io.*;
public class DeadLock {
	public static void  main(String[] args) throws IOException{
		Input obj=new Input(0,0);
		obj.getDigit();
		String str1,str2;  
		str1=GetString.str();
		str2=GetString.str();
		System.out.println(str1+"    "+str2);
		int s,p;
		s=Integer.parseInt(str1);
		p=Integer.parseInt(str2);
		obj.ensure(s,p);
		int [][] matrix=obj.getMatrix();
		int[] sMatrix=obj.getSource();
		int[] trace=new int[sMatrix.length];
		if(argorithm(matrix,sMatrix,trace))
			System.out.println("The processes are being in the safe condition");
		else
			System.out.println("The processes are not in the safe condition");
		System.out.println("To keep the safe condition,you should follow the ways:");
		for(int l=0;l<trace.length;++l){
			System.out.print(trace[l]+" ");
		}
		System.out.println();
	}
	static public boolean argorithm(int[][] a,int[] b,int[] c){
		int i_a=a.length;
		int j_a=a[0].length;
		for(int t=0;t<i_a;++t){
			for(int i=0;i<i_a;++i){
				if(processEnd(a[i])){
					c[t]=i+1;
					continue;
				}
				else{
					if(compare(a[i],b)){
						for(int j=0;j<j_a;++j){
							b[j]+=a[i][j];
						    a[i][j]=0;
					    }
						c[t]=i+1;
						 break;
					}
					else
						continue;
				}
			}
		}
		if(!isfinish(a))
			return false;
		else
			return true;
	}
	static boolean processEnd(int[] a){
		int sum=0;
		for(int i=0;i<a.length;++i)
			sum+=a[i];
		if(sum==0)
			return true;
		else
			return false;
	}
	static public boolean compare(int[] a,int[] b){
		boolean answer=true;
		for(int i=0;i<a.length;++i){
			if(a[i]>b[i])
			{
				answer=false;
				break;
			}
		}
		return answer;
	}
	static boolean isfinish(int[][] a){
		int sum=0;
		int i,j;
		for(i=0;i<a.length;++i)
			for(j=0;j<a[i].length;++j)
				sum+=a[i][j];
		if(sum==0)
			return true;
		else
			return false;
	}
}

⌨️ 快捷键说明

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