Em Andamento

Bankers Algorithm

For this project, you will write a multithreaded program that implements the banker’s algorithm discussed

in Section 7.5.3. Several customers 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 that leaves the system in an unsafe state will

be denied. This programming assignment combines three separate topics: (1) multithreading, (2)

preventing race conditions, and (3) deadlock avoidance.

The Banker

The banker will consider requests from n customers for m resources types. The banker will keep track of

the resources using the following data structures:

/* these may be any values >= 0 */

#define NUMBER OF CUSTOMERS 5

#define NUMBER OF RESOURCES 3

/* the available amount of each resource */

int available[NUMBER OF RESOURCES];

/*the maximum demand of each customer */

int maximum[NUMBER OF CUSTOMERS][NUMBER OF RESOURCES];

/* the amount currently allocated to each customer */

int allocation[NUMBER OF CUSTOMERS][NUMBER OF RESOURCES];

/* the remaining need of each customer */

int need[NUMBER OF CUSTOMERS][NUMBER OF RESOURCES];

The Customers

Create n customer threads that request and release resources from the bank. The customers will continually

loop, requesting and then releasing random numbers of resources. The customers’ requests for resources

will be bounded by their respective values in the need array. The banker will grant a request if it satisfies

the safety algorithm. If a request does not leave the system in a safe state, the banker will deny it. Function

prototypes for requesting and releasing resources are as follows:

int request resources(int customer num, int request[]);

int release resources(int customer num, int release[]);

These two functions should return 0 if successful (the request has been granted) and –1 if unsuccessful.

Multiple threads (customers) will concurrently access shared data through these two functions. Therefore,

access must be controlled through mutex locks to prevent race conditions.

Implementation

You should invoke your program by passing the number of resources of each type on the command line.

For example, if there were three resource types, with ten instances of the first type, five of the second type,

and seven of the third type, you would invoke your program follows:

./[url removed, login to view] 10 5 7

The available array would be initialized to these values. You may initialize the maximum array (which

holds the maximum demand of each customer) using any method you find convenient.

Habilidades: Java

Ver mais: types of data structures in java, types of data structures in c, types of data structures, types of algorithm, types data structures, type of data structures, two types of data structures, programming algorithm example, program algorithm example, multithreading programming, line algorithm, java 1.5 for loop, implementation of data structures, first command bank, find-s algorithm in c, find maximum algorithm, example of an algorithm in programming, example of an algorithm, example of algorithm in programming, example of algorithm, example of a algorithm, example for algorithm, example algorithm, define data structures in c, define algorithm in programming

Acerca do Empregador:
( 5 comentários ) Suva, Fiji

ID do Projeto: #10492768

Premiar a:

thewebscraper

Great day! I can help you with your project with quality. I'll put some comments also for you to understand and I look forward to your acceptance. Have a great day!

$35 AUD em 0 dias
(1 Comentário)
0.8

3 freelancers estão ofertando em média $82 para este trabalho

$111 AUD in 2 dias
(5 Comentários)
2.5
AyushBangalore

5+ years experience of developing java applications. Written multithreaded code and solved problems such as consumer producer.

$100 AUD em 1 dia
(4 Comentários)
2.2