Skip to content

Commit acf6d8e

Browse files
committed
fixed typo
1 parent 64f93bb commit acf6d8e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

bankers_algorithm.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"\n",
7272
"# The main function to demonstrate the Banker's algorithm\n",
7373
"if __name__ == \"__main__\":\n",
74+
" # case 1\n",
7475
" max_resources = [\n",
7576
" [7, 5, 3],\n",
7677
" [3, 2, 2],\n",
@@ -105,6 +106,7 @@
105106
"metadata": {},
106107
"outputs": [],
107108
"source": [
109+
"# case 2\n",
108110
"if __name__ == \"__main__\":\n",
109111
" max_resources = [\n",
110112
" [7, 5, 3],\n",

same_python_file/bankers_algorithm.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def check_safety(self):
6363

6464
# The main function to demonstrate the Banker's algorithm
6565
if __name__ == "__main__":
66+
67+
# case 1
6668
max_resources = [
6769
[7, 5, 3],
6870
[3, 2, 2],
@@ -89,3 +91,28 @@ def check_safety(self):
8991
print("Request is safe to be granted.")
9092
else:
9193
print("Request may lead to a deadlock and cannot be granted.")
94+
95+
96+
# case 2
97+
max_resources = [
98+
[7, 5, 3],
99+
[3, 2, 2],
100+
[9, 0, 2],
101+
]
102+
103+
allocated_resources = [
104+
[0, 1, 0],
105+
[2, 0, 0],
106+
[3, 0, 2],
107+
]
108+
109+
total_resources = [10, 5, 7]
110+
111+
banker = BankersAlgorithm(max_resources, allocated_resources, total_resources)
112+
request = [5, 0, 0]
113+
process_id = 0
114+
115+
if banker.is_safe_state(request, process_id):
116+
print("Request is safe to be granted.")
117+
else:
118+
print("Request may lead to a deadlock and cannot be granted.")

0 commit comments

Comments
 (0)