Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote