# Project 3 Banker Algorithm – These are the instructions for your third programming project.

Project 3 Banker Algorithm

Due Date: 11/7/21 11:59pm

These are the instructions for your third programming project. Recall that the project is done by group of 2 students. You could submit only one copy with two names.

Problem: In this project, you will write a Java/C++ program that implements the banker’s algorithm discussed in Section 7.5.3. Several customers (multithreading) request and release resources from the bank. The banker will grant a request only if it leaves the system in a safe state. A request is denied if it leaves the system in an unsafe state.

The bank will employ the strategy outlined in Section 7.5.3, whereby it will consider requests from n customers for m resources. The bank will keep track of the resources using the following data structures:

int numberOfCustomers; // the number of customers int numberOfResources; // the number of customers

int [] available; // the available amount of each resource int[][] maximum; // the maximum demand of each customer

int[][] allocation; // the amount currently allocated to each customer int[][] need; // the remaining needs of each customer

The functionality of the bank appears in the interface shown in below Figure 7.13 (Java). The implementation of this interface will require adding a constructor that is passed the number of resources initially available. For example, suppose we have three resource types with 10, 5, 7 resources initially available. In this case, we can create an implementation of the interface using the following code,

Bank bankExample = new BankImpl(10, 5, 7);

The bank will grant a request if the request satisfied the safety algorithm outlined in 7.5.3. If granting the request does leave the system in a safe state, the request is denied.

Testing:

Use input values below to test your code, determine whether or not request a. or b is safe or not, write in your report. If the state is safe, illustrate the order in which the threads may complete. Otherwise, illustrate why the state is unsafe.

Allocation Max

 A B C D A B C D T0 3 0 1 4 5 1 1 7 T1 2 2 1 0 3 2 1 1 T2 3 1 2 1 3 3 2 1 T3 0 5 1 0 4 6 1 2 T4 4 2 1 2 6 3 2 5

a. Available = (0, 3, 0, 1) safe or not, if yes, what is the execution sequence?

b. Available = (1, 0, 0, 2) safe or not, if yes, what is the execution sequence?

What to hand in?

• A report includes problem statement, analysis, algorithm design, class prototype (class contract), program Input/Output, and tested results (analysis your result to see if it is correct).

• The source program (named your file “project3.java”)

• You could either submit through Blackboard or my email box. Each program should have the following in the beginning:

// Program Name: <The name of your program file>

// Programmer: <Your name here>, <ID>

// Assignment Number: <put project number here, e.g. Project #3>

// Purpose: <A short problem description>