Question

In: Computer Science

six resources labeled A to F.

In the code below, three processes are competing for six resources labeled A to F.

a. Using a resource allocation graph, show the possibility of a deadlock in this implementation.

b. Modify the order of some of the get requests to prevent the possibility of any deadlock. You cannot move requests across procedures, only change the order inside each procedure. Use a resource allocation graph to justify your answer.

In the code below, three processes are competing for six

 

Solutions

Expert Solution

.

 

There is a deadlock if the scheduler goes, for example: P0-P1-P2-P0-P1-P2 (line by line): Each of the 6 resources will then be held by one process, so all 3 processes are now blocked at their third line inside the loop, waiting for a resource that another process holds. This is illustrated by the circular wait (thick arrows) in the RAG above: P0→C→P2→D→P1→B→P0.

 

b.  

Any change in the order of the get() calls that alphabetizes the resources inside each process code will avoid deadlocks. More generally, it can be a direct or reverse alphabet order, or any arbitrary but predefined ordered list of the resources that should be respected inside each process.

 

Explanation: if resources are uniquely ordered, cycles are not possible any more because a process cannot hold a resource that comes after another resource it is holding in the ordered list. See this remark in Section 6.2 about Circular Wait Prevention. For example:

A                     B                     C

B                     D                     D

C                     E                      F

 

With this code, and starting with the same worst-case scheduling scenario P0-P1-P2, we can only continue with either P1-P1-CR1… or P2-P2-CR2…. For example, in the case P1-P1, we get the following RAG without circular wait:

 

After entering CR1, P1 then releases all its resources and P0 and P2 are free to go. Generally the same thing would happen with any fixed ordering of the resources: one of the 3 processes will always be able to enter its critical area and, upon exit, let the other two progresses.


Generally the same thing would happen with any fixed ordering of the resources: one of the 3 processes will always be able to enter its critical area and, upon exit, let the other two progresses.

Related Solutions

Consider the following figure. A hexagon has six labeled vertices and a dashed line segment which...
Consider the following figure. A hexagon has six labeled vertices and a dashed line segment which divides the hexagon into a trapezoid and rectangle. The first side is horizontal, starts at vertex R, goes to the right, and ends at vertex S. The second side is vertical, starts at vertex S, goes up, and ends at vertex T. The third side starts at vertex T, goes up and to the right, and ends at vertex V. The fourth side is...
Write a program that simulates a vending machine. The machine holds six snack items labeled them...
Write a program that simulates a vending machine. The machine holds six snack items labeled them 1 through 6. The program should initially display a menu of items along with their prices: Vending Machine 1. Roasted Almonds --> $1.25 2. Pretzels --> $1.75 3. Chewing Gum --> $0.90 4. Mints --> $0.75 5. Chocolate bar --> $1.50 6. Cookies --> $2.00 The program then should ask the user to enter the item to purchase along with a sum of money....
F. Describe (you must provide a drawing with axes labeled and equilibrium identified along with a...
F. Describe (you must provide a drawing with axes labeled and equilibrium identified along with a short explanation) what happens to the equilibrium interest rate when: (i) inflation is expected to decrease (3 Points) (ii) the stock market crashes (3 Points) (iii) government deficit goes down (3 Points) (iv) money supply decreases (3 Points)
List six types of resources available to us in the production process of goods and services
List six types of resources available to us in the production process of goods and services
In the diagram below, there are two charges of and and six points (a through f)...
In the diagram below, there are two charges of +q and -q and six points (a through f) at various distances from the two charges. (Intro 1 figure) You will be asked to rank changes in the electric potential along paths between pairs of points. Q: Using the diagram to the left, rank each of the given pathson the basis of the change in electric potential. Rank the largest-magnitude positive change (increase in electric potential)as largest and the largest-magnitude negative...
1. L. F. Gilbreath, the vice president of human resources for a major U.S. airline, wants...
1. L. F. Gilbreath, the vice president of human resources for a major U.S. airline, wants to compare four programs for training employees to perform a certain task. Twenty employees are randomly assigned to the training programs, with five in each program. At the end of the training period, the number of times each employee can perform the task in a five-minutes period is recorded as follows: PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 9 10 12 9 12...
1, Let f(x)=x^4-4x+10 Find the intervals of increase and decrease. A well labeled sign chart is...
1, Let f(x)=x^4-4x+10 Find the intervals of increase and decrease. A well labeled sign chart is usually enough here. 2, For the same function find relative extrema as ordered pairs. 3, For the same function find intervals of concavity (concave up/down) and any inflection points as ordered pairs.
Bulb A is labeled with power P and voltage V, bulb B is labeled with power...
Bulb A is labeled with power P and voltage V, bulb B is labeled with power P/2 and voltage V. These two bulbs are connected in series and then to some source of voltage, which is unknown. Which one produces greater illumination?
Use the dependent variable (labeled Y) and one of the independent variables (labeled X1, X2, and...
Use the dependent variable (labeled Y) and one of the independent variables (labeled X1, X2, and X3) in the data file. Select and use one independent variable throughout this analysis. Use Excel to perform the regression and correlation analysis to answer the following. Generate a scatterplot for the specified dependent variable (Y) and the selected independent variable (X), including the graph of the "best fit" line. Interpret. Determine the equation of the "best fit" line, which describes the relationship between...
Use the dependent variable (labeled Y) and one of the independent variables (labeled X1, X2, and...
Use the dependent variable (labeled Y) and one of the independent variables (labeled X1, X2, and X3) in the data file. Select and use one independent variable throughout this analysis. Use Excel to perform the regression and correlation analysis to answer the following. The week 6 spreadsheet can be helpful in this work. 1. Generate a scatterplot for the specified dependent variable (Y) and the selected independent variable (X), including the graph of the "best fit" line. Interpret. 2 Determine...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT