Banker's Algorithm

Closed Posted 7 years ago Paid on delivery
Closed Paid on delivery

Banker’s Algorithm

For this project, you will write a multithreaded program that implements the

banker’s algorithm. 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. as

outlined in Section 7.5.3. 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 outlined in Section 7.5.3.1. 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. Both the Pthreads

and Windows APIs provide mutex locks.

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:

./[login to view URL] 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.

C Programming

Project ID: #10526237

About the project

13 proposals Remote project Active 7 years ago

13 freelancers are bidding on average $33 for this job

hbxfnzwpf

I am very proficient in c and c++. I have 16 years c++ developing experience now, and have worked for more than 6 years. My work is online game developing, and mainly focus on client side, using c++ under windows envir More

$70 USD in 1 day
(131 Reviews)
6.9
ziombski

I can solve your problem within 1 day. Quickly and well. I have a lot of experience with C and algorithms. I have recently graduated from the second-best IT university in Europe (University of Warsaw).

$50 USD in 1 day
(18 Reviews)
4.5
Anurag7

Hi, I have 11 years of experience. I have done such many project. I understood your requirement and I shall implement it within 1 day. Thanks, Anurag

$30 USD in 1 day
(16 Reviews)
4.3
vikassaini37853

my team members are either from NIT or A grade colleges. Also we are experienced in such kind of tasks including C, C++ and Java. Check sample website in my portfolio

$25 USD in 2 days
(1 Review)
1.1
vvimalirock1

Hi i am a computer science student and i have done same programs for my operating system lab. I even have the program ready If you are interested Contact me asap.I will deliver the program by today itself.

$25 USD in 1 day
(1 Review)
0.8
xtoferbp

Hi! I have experience doing scientific research deploying C algorithms for solution of PDE, MC, etc. I can complete your task on time and with high quality Only contact with me Regards

$15 USD in 3 days
(0 Reviews)
0.0
dovantuan

Update every day

$25 USD in 3 days
(0 Reviews)
0.0
sureship

I am aware of this algorithm. I can get this done for you in 2-3 days. Do you have a document also for this? Which langaug do you want the code to be in?

$55 USD in 2 days
(0 Reviews)
0.0
blitz003

Just give me 30 mins and let's see what I can do. If after 30 minutes you're not impressed just give it to someone else. Deal or no deal?

$10 USD in 1 day
(1 Review)
0.0
ankita0389

A proposal has not yet been provided

$33 USD in 3 days
(0 Reviews)
0.0