Assume that a finite number of resources of a single resource type must be managed. Processes may
Question:
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:
#define MAX RESOURCES 5
int available resources = MAX RESOURCES;
When a process wishes to obtain a number of resources, it invokes the decrease 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 the decrease count() function:
/* increase available resources by count */
int increase count(int count) {
available resources += count;
return 0;
}
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 semaphore, fix the race condition.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Value at Risk The New Benchmark for Managing Financial Risk
ISBN: 978-0071464956
3rd edition
Authors: Philippe Jorion
Question Posted: