Banker's algorithm: Difference between revisions
m
→{{header|Perl 6}}: replace loop/last, further tidying
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: curly out of place) |
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: replace loop/last, further tidying) |
||
Line 964:
=={{header|Perl 6}}==
▲# based on the Python3 solution by Shubham Singh(SHUBHAMSINGH10)
my @maxm = <3 3 2 2>, <1 2 3 4>, <1 3 5 0>;
my
▲my @avail = <3 1 1 2>; # Available instances of resource
▲my @maxm = <3 3 2 2>, <1 2 3 4>, <1 3 5 0>; # Maximum R that can be allocated to processes
# Function to find the system is in safe state or not
sub isSafe(\
my
my
my
my @
my @safe-sequence;
# While all processes are not finished
my $count = 0;
while $count < P {
my $found = False;
for ^P -> \p {
#
if @
@unfinished[p] = False;
$count +=
}
}
# If we could not find a next process in safe sequence
return False, "System is not in safe state." unless $found;
}
# If system is in safe state then safe sequence will be as below
return True, "Safe sequence is: " ~ @
}
# Check if system is in a safe state
my ($safe-state,$status-message) = isSafe @avail, @maxm, @allot;
say "Safe state? $safe-state";
say "Message: $status-message";</lang>
{{out}}
<pre>
available resources: 5 3 6 6
available resources: 6 5 7 6
Safe state? True
Message: Safe sequence is: 0 1 2</pre>
|