Operating systems question 3.. The following program segment is used to manage a
ID: 3597721 • Letter: O
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 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..
Explanation / Answer
/** 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;;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.