Question

In: Computer Science

Consider the following program

Consider the following program:
boolean blocked [2];
int turn;
void P (int id)
{
while (true) {
blocked[id] = true;
while (turn != id) {
while (blocked[1-id])
/* do nothing */;
turn = id;
}
/* critical section */
blocked[id] = false;
/* remainder */
}
}
void main()
{
blocked[0] = false;
blocked[1] = false;
turn = 0;
parbegin (P(0), P(1));
}

Solutions

Expert Solution

Consider the case in which turn equals 0 and P(1) sets blocked[1] to true and then finds blocked[0] set to false. P(0) will then set blocked[0] to true, find turn = 0, and enter its critical section. P(1) will then assign 1 to turn and will also enter its critical section. The error was pointed out in [RAYN86].


 P(1) will then assign 1 to turn and will also enter its critical section. The error was pointed out in [RAYN86].

Related Solutions

Consider the following program. There are 11 statements in the program starting with int x; Show...
Consider the following program. There are 11 statements in the program starting with int x; Show the memory allocated for the program in the stack and heap for each statement. Also, show any values assigned to each of these memory locations. In other words, you will show 11 stacks and 11 heaps as the answer to your question. #include <iostream> using namespace std; int main() { int x; // Stmt 1 int * y; // Stmt 2 y = new...
Consider the following program. // This program averages 3 test scores. It repeats as // many...
Consider the following program. // This program averages 3 test scores. It repeats as // many times as the user wishes. #include <iostream> using namespace std; int main() { int score1, score2, score3; // Three scores double average; // Average score char again; // To hold Y or N input do { // Get three scores. cout << "Enter 3 scores and I will average them: "; cin >> score1 >> score2 >> score3; // Calculate and display the average....
A statistical program is recommended. Consider the following data for a dependent variable y and two...
A statistical program is recommended. Consider the following data for a dependent variable y and two independent variables, x1 and x2. x1 x2 y 30 12 94 47 10 108 25 17 112 51 16 178 40 5 94 51 19 175 74 7 170 36 12 117 59 13 142 76 16 211 (a) Develop an estimated regression equation relating y to x1. (Round your numerical values to one decimal place.)ŷ =   Predict y if x1 = 43. (Round...
Consider the following linear program:    MAX Z = 25A + 30B    s.t. 12A +...
Consider the following linear program:    MAX Z = 25A + 30B    s.t. 12A + 15B ≤ 300    8A + 7B ≤ 168 10A + 14B ≤ 280    Solve this linear program graphically and determine the optimal quantities of A, B, and the    value of Z. Show the optimal area.
Consider the following Java program. Describe what it does in response to specific operations of the...
Consider the following Java program. Describe what it does in response to specific operations of the mouse, and how it does it. (You are encouraged to run the program for yourself to test its behavior. Then read through the program carefully to understand how that behavior arises.) import java.awt.event.*; import javax.swing.*; public class MouseWhisperer extends JFrame implements MouseListener {     MouseWhisperer() {         super("COME CLOSER");         setSize(300,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         addMouseListener(this);         setVisible(true);     }     public void mouseClicked(MouseEvent e)...
Consider the following code section of a parallel program that computes the sum of n values...
Consider the following code section of a parallel program that computes the sum of n values using p processors: my_sum = 0; my_first_i = ... ; my_last_i = ... ; for(my_i = my_first_i; my_i < my_last_i; my_i++) { my_x = Compute_next_value(...); my_sum += my_x; } Here the prefix my_ indicates that each core is using its own, private variables, and each core can execute this block of code independently of the other cores. Devise formulas for the functions that calculate...
A statistical program is recommended. Consider the following data for two variables, x and y. x...
A statistical program is recommended. Consider the following data for two variables, x and y. x 22 24 26 30 35 40 y 12 20 33 35 40 36 (a) Develop an estimated regression equation for the data of the form ŷ = b0 + b1x.  (Round b0 to one decimal place and b1 to three decimal places. ŷ = (b) Use the results from part (a) to test for a significant relationship between x and y. Use α = 0.05....
A statistical program is recommended. Consider the following data for two variables, x and y. x...
A statistical program is recommended. Consider the following data for two variables, x and y. x 9 32 18 15 26 y 11 20 22 17 22 (a) Develop an estimated regression equation for the data of the form ŷ = b0 + b1x. (Round b0 to two decimal places and b1 to three decimal places.) ŷ = Comment on the adequacy of this equation for predicting y. (Use α = 0.05.) The high p-value and low coefficient of determination...
A statistical program is recommended. Consider the following data for two variables, x and y. xi...
A statistical program is recommended. Consider the following data for two variables, x and y. xi 135 110 130 145 175 160 120 yi 145 100 120 120 135 130 110 (a) Compute the standardized residuals for these data. (Round your answers to two decimal places.) xi yi Standardized Residuals 135 145 2.11 Incorrect: Your answer is incorrect. 110 100 -0.73 Incorrect: Your answer is incorrect. 130 120 145 120 175 135 160 130 120 110 Do the data include...
Consider the following linear program:    MAX Z = 25A + 30B    s.t. 12A + 15B ≤...
Consider the following linear program:    MAX Z = 25A + 30B    s.t. 12A + 15B ≤ 300    8A + 7B ≤ 168   10A + 14B ≤ 280    Solve this linear program graphically and determine the optimal quantities of A, B, and the    value of Z. Show the optimal area.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT