essCount
{{return _processCount; }
{(_ processCount == value) return;
_ processCount=value; ( ProcessCount );=new int [_processCount, 2];
}
} int _freеResources; int FreеResources
{{return _freеResources; }
{(_ freеResources == value) return;
_ freеResources=value; ( FreеResources );
}
} int [,] _processes; int [,] Processes
{{return _processes; }
{
_ processes=value; ( Processes );
}
} RelayCommand _deadlockPreventingCommand; RelayCommand DeadlockPreventingCommand
{
{(_ deadlockPreventingCommand == null)
{
_ deadlockPreventingCommand=new RelayCommand (PreventDeadlock, CanPreventDeadlock);
} _ deadlockPreventingCommand;
} {_deadlockPreventingCommand=value; }
} PreventDeadlock ()
{= raquo ;; completed=new List lt; int gt; (); released=true; tmp=FreеResources; (completed.Count lt; ProcessCount)
{= false; (int i=0; i lt; ProcessCount; i ++)
{
if (completed.Contains (i)) continue;
var has=Processes [i, 0];
var need=Processes [i, 1];
if (need gt; has)
{
var dif=need - has;
if (FreеResources gt;=dif)
{
FreеResources +=has;
completed.Add (i);
released=true;
AddLog (string.Format ( Виконано {0} процес, вільний ресурс {1} raquo ;, i, FreеResources));
break;
}
}
else
{
FreеResources +=has;
completed.Add (i);
released=true;
AddLog (string.Format ( Виконано {0} процес, вільний ресурс {1} raquo ;, i, FreеResources));
break;
}
} (released == false)
{
break;
}
} еResources=tmp; .Show (released? Всі процеси виконані : Недостатньо вільних ресурсів );
} CanPreventDeadlock ()
{ProcessCount gt; 0;
} string _log; string Log
{{return _log; }
{
_ log=value; ( Log );
}
} AddLog (string msg)
{+=msg + n raquo ;;
}
}
}