subject
Engineering, 10.04.2020 21:12 Osmin

The decrease_count() function in the previous exercise currently returns 0 if sufficient resources are available and −1 otherwise. This leads to awkward programming for a process that wishes to obtain a number of resources: while (decrease_count(count) == -1) ; Rewrite the resource-manager code segment using a monitor and condition variables so that the decrease_count() function suspends the process until sufficient resources are available. This will allow a process to invoke decrease_count() by simply calling:

decrease_count(count);

The process will return from this function call only when sufficient resources are available.

Previous Code:

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

} }

ansver
Answers: 1

Another question on Engineering

question
Engineering, 04.07.2019 08:10
Which of the following is an easy way to remember the modified “x” tire rotation? a. nondrive wheels straight, cross the drive wheels b. drive wheels straight, cross the nondrive wheels c. drive wheels crossed, nondrive wheels straight d. drive wheels crossed, nondrive wheels crossed
Answers: 1
question
Engineering, 04.07.2019 18:10
Water at 55c flows across a flat plate whose surface temperature is held constant at 95c. if the temperature gradient at the plate's surface for a given value of x is 18 c/mm, find a) local heat transfer coefficient. b) heat flux
Answers: 3
question
Engineering, 04.07.2019 18:10
Slip occurs via two partial dislocations because of (a) the shorter path of the partial dislocation lines; (b) the lower energy state through partial dislocations; (c) the charge balance.
Answers: 1
question
Engineering, 04.07.2019 18:10
An air compression refrigeration system is to have an air pressure of 100 psia in the brine tank and an allowable air temperature increase of 60°f for standard vapor compression cycle temperatures of 77 f entering the expansion cylinder and 14 f entering the compression cylinder, calculate the coefficient of performance a. 2.5 b 3.3 c. 4.0 d. 5.0
Answers: 3
You know the right answer?
The decrease_count() function in the previous exercise currently returns 0 if sufficient resources a...
Questions
question
Social Studies, 11.01.2020 00:31
question
Mathematics, 11.01.2020 00:31
question
Mathematics, 11.01.2020 00:31
question
English, 11.01.2020 00:31
question
Geography, 11.01.2020 00:31
question
Social Studies, 11.01.2020 00:31