Assume that a finite number of resources of a single resource type mustbe managed

Chapter 5, Problem 5.37

(choose chapter or problem)

Assume that a finite number of resources of a single resource type mustbe managed. Processes may ask for a number of these resources and willreturn them once finished. As an example, many commercial softwarepackages provide a given number of licenses, indicating the number ofapplications that may run concurrently. When the application is started,the license count is decremented. When the application is terminated, thelicense count is incremented. If all licenses are in use, requests to startthe application are denied. Such requests will only be granted whenan existing license holder terminates the application and a license isreturned.The following program segment is used to manage a finite number ofinstances of an available resource. The maximum number of resourcesand the number of available resources are declared as follows:#define MAX RESOURCES 5int available resources = MAX RESOURCES;When a process wishes to obtain a number of resources, it invokes thedecrease count() 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;else {available resources -= count;return 0;}}When a process wants to return a number of resources, it calls theincrease count() function:/* increase available resources by count */c. Using a semaphore or mutex lock, fix the race condition. It ispermissible to modify the decrease count() function so that thecalling process is blocked until sufficient resources are available.int increase count(int count) {available resources += count;return 0;}The preceding program segment produces a race condition. Do thefollowing:a. Identify the data involved in the race condition.b. Identify the location (or locations) in the code where the racecondition occurs.

Unfortunately, we don't have that question answered yet. But you can get it answered in just 5 hours by Logging in or Becoming a subscriber.

Becoming a subscriber
Or look for another answer

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back