Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #define MAX_RESOURCES 5 int available_resources = MAX_RESOURCES; /* decrease available resources by count resources */ /* return 0 if sufficient resources

#include

#include

#include

#include

#define MAX_RESOURCES 5

int available_resources = MAX_RESOURCES;

/* decrease available resources by count resources */ /* return 0 if sufficient resources available, */

/* otherwise return -1 */

int decrease_count(int count)

{

synchronized(available_resources)

{

while (available_resources < count)

{

available_resources.wait();

}

available_resources -= count;

return 0;

}

}

/* increase available_resources by count */

int increase_count(int count)

{

synchronized(available_resources)

{

available_resources += count;

available_resources.notify();

}

}

Assume that a finite number of resources of a single resource type must be managed. Processes may ask for a number of these resources and will return them once finished. As an example, many commercial software packages provide a given number of licenses, indicating the number of applications that may run concurrently. When the application is started, the license count is decremented. When the application is terminated, the license count is incremented. If all licenses are in use, requests to start the application are denied. Such a request will be granted only when an existing license holder terminates the application and a license is returned. Design your algorithm, implement your code and demonstrate an example.

Design: Code: Output:

I am not sure how to set up the program in C language.

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions