# Data Inconsistency / Critical Section

Consider the following program segments for two different processes (P1, P2) executing concurrently, where a and b are not shared variables, but x starts at zero and is a shared variable.

**Case 1:**

"Processor #1 "

for (a = 1; a <= 3; a++)

x = x + 1;

"Processor #2"

for (b = 1; b <= 3; b++)

x = x + 1;

**Case 2:**

"Processor #1"

x = 0; x = 0;

for (a = 1; a <= 3; a++)

x = x + 1;

"Processor #2"

for (b = 1; b <= 3; b++)

x = x + 1;

a. If the processes P1 and P2 execute only once at any speed, what are the possible resulting values of x in Case 1 and Case 2? Explain your answers.

b. Suggest some modifications on the original code to eliminate the problem. (Answer part (b) only if you have identified data inconsistency / critical section problems in part (a))

Questions by fatema sawan

Showing Answers 1 - 3 of 3 Answers

#### Related Answered Questions

#### Related Open Questions

## Data Inconsistency / Critical Section

Case 1:

"Processor #1 "for (a = 1; a <= 3; a++)

x = x + 1;

"Processor #2"

for (b = 1; b <= 3; b++)

x = x + 1;

Case 2:

"Processor #1"x = 0; x = 0;

for (a = 1; a <= 3; a++)

x = x + 1;

"Processor #2"

for (b = 1; b <= 3; b++)

x = x + 1;

a. If the processes P1 and P2 execute only once at any speed, what are the possible resulting values of x in Case 1 and Case 2? Explain your answers.

b. Suggest some modifications on the original code to eliminate the problem. (Answer part (b) only if you have identified data inconsistency / critical section problems in part (a))

fatema sawanProfile Answers by fatema sawan Questions by fatema sawan

Questions by fatema sawan

## Related Answered Questions

## Related Open Questions