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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!