Показать сообщение отдельно
Старый 08.12.2001, 20:54
Countach вне форума Посмотреть профиль Отправить личное сообщение для Countach Найти все сообщения от Countach
  № 3  
Countach
 
Аватар для Countach

Регистрация: Mar 2001
Адрес: Cyprus, Nicosia
Сообщений: 795
Отправить сообщение для Countach с помощью ICQ
Ребят что никто совсем такое не делал во флешке, вот поправил ошибки в первой половине проги
она растет и растет, как не будет ли тормозить ???
Код:
//##### BANKER'S ALGORITHM SOURCE CODE #####

// Declaration of data structures
NoResources = 6;
NoProcesses = 5;
// total number of resources
AvailI = new Array(NoResources);
AvCons = new Array(4, 5, 16, 2, 12, 64);
AvailI = AvCons;
// initialization of available resources in the system
// fill up the array for the number of max resources
MaxI = new Array();
for (i=0; i<NoProcesses; i++) {
	MaxI[i] = new Array();
	for (j=0; j<NoResources; j++) {
        temp=AvailI[j];
		MaxI[i][j] = random(temp);
		trace (MaxI[i][j]);
	}
}
separate='----------------------------------';
trace(separate);
// fill up the array with the allocated resources
AllocI = new Array();
for (i=0; i<NoProcesses; i++) {
	AllocI[i] = new Array();
	for (j=0; j<NoResources; j++) {
		AllocateI = MaxI[i][j];
                Allocate = random(AllocateI);
		AllocI[i][j] = Allocate;
		if (Allocate>AvailI[j]) {
	           j--;
		} else if (AvailI[j] == 0) {
	             AllocI[i][j] = 0;
		   } else if (Allocate<=AvailI[j]) {
			AvailI[j] = AvailI[j]-Allocate;
                        trace (AllocI[i][j]);
		     }
	}
}
separate='----------------------------------';
trace(separate);
// fill up the array with how many resources each process may request
NeedI = new Array();
for (i=0; i<NoProcesses; i++) {
	NeedI[i] = new Array();
	for (j=0; j<NoResources; j++) {
		NeedI[i][j] = MaxI[i][j]-AllocI[i][j];
                trace (NeedI[i][j]);
	}
}


//------------end of initialization-------------------


//-------------------request--------------------------


Row=Random(NoProcesses);
Column=Random(NoResources);
Request=Random(Need[Row][Column]); 

if ((Request<=NeedI[Row][Column]) && (Request<=AvailI[Column])) {
   AvailI[Column]=AvailI[Column]-Request;
   AllocI[Row][Column]=AllocI[Row][Column]+Request;
   NeedI[Row][Column]=NeedI[Row][Column]-Request;
}

Finish = new Array();
Finish [NoResources];
for (i=0; i<NoResources; i++) {
   Finish[i]=false;
}

Status = new Array();
Status [NoProcesses];
for (i=0; i<NoProcesses; i++) {
   Status[i]=false;
}

counter=0;
precounter=0;
repeat
   for (Row=0; Row<NoProcesses; Row++) {
      for (Column=0; Column<NoResources; Column++) {
         if ((NeedI[Row][Column]<=AvailI[Column]) && (Status[Row]==false)) {
            AvailI[Column]+=AllocI[Row][Column];
            Finish[Column]=True;
         }
      }
      Pid=true;
      for(Column=0; Column<NoResources; Column++) {
         if (Finish[Column]==false) {
            Pid=false;
         }
      }
      Status[Row]=Pid;
      if (Pid==true) {
         counter++;
      }
   }
   Pst=true;
   for (Row=0; Row<NoProcesses; Row++) {
      if (Status[Row]==false) {
         Pst=false;
      }
   }
   if Pst==true {
      gotoAndPlay ("SAFE");
   }
   Signal=false;
   if counter>precounter {
      precounter=counter;
      signal=true;
   }
until signal==false;
gotoAndPlay ("UNSAFE");
__________________
Кто рано встает, тому... спать весь день хочется.