Question: #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
Get step-by-step solutions from verified subject matter experts
