Question
Operating systems question 3.. The following program segment is used to manage a nite number of instances of an available resource.. The maximum number of
Operating systems question
3.. The following program segment is used to manage a nite number of instances of an available resource.. The maximum number of resourc es and the number of available resources are declared
#ddefine 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 coun t resources *//
/** return 0 if sufficient resources available,, *//
/** otherwise return - 1 *//
int decrease count((iint count)) {
if (aavailable 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((iint 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 (oor locations)) in the code where the race condition occurs..
c.. Using a semaphore,, x the race condition..
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started