Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a UNIX environment using C language, please explain how to tackle this problem (please provide comments, will thumbs up): Banker's Algorithm For this project,

In a UNIX environment using C language, please explain how to tackle this problem (please provide comments, will thumbs up):

image text in transcribed

Banker's Algorithm For this project, you will write a multithreaded program that implements the banker's algorithm 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. Several customers request and The Banker The banker will consider requests from n customers for m resources types. following data structures: The banker will keep track of the resources using the /*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 by their respective values in the need array. The banker will grant a request if it satisfies the safety algorithm leave the system in a safe state, the banker will deny it. Function prototypes fo will be bounded If a request does not r reque sting 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 APls provide mutex locks. Implementation You should invoke your program by passing the number of resources of ea 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: /a.out 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science For Dummies

Authors: Lillian Pierson ,Jake Porway

2nd Edition

1119327636, 978-1119327639

More Books

Students also viewed these Databases questions

Question

explain the need for human resource strategies in organisations

Answered: 1 week ago

Question

describe the stages involved in human resource planning

Answered: 1 week ago