Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

-once finished-will return them. 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 requests will only be

granted when an existing license holder terminates the application and

a license is returned.

The following program segment is used to manage a finite number of

instances of an available resource. The maximum number of resources

and the number of available resources are declared as follows:

image text in transcribed

When a process wants to return a number of resourcesf it calls the

increase_count () function:

image text in transcribed

The preceding program segment produces a race condition. Do the

following:

a. Identify the data involved in the race condition.

b. Identify the location (or locations) in the code where the race

condition occurs.

c. Using a semaphoref fix the race condition. It is ok to modify the

decrease_count () fun.ction so that the calling process is blocked

until sufficient resources are available.

#define MAX-RESOURCES 5 int available resources-MAX RESOURCES; When a process wishes to obtain a number of resources, it invokes the decrease count (O) function: /* decrease available resources by count resources*/ /*return 0 if sufficient resources available,/ /*otherwise return -1* int decrease count (int count) [ if (available resources count) return -1; available resources return 0; else count

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

More Books

Students also viewed these Databases questions