Question

• Code where a process is changing shared data memory P1 X = X + 2; X 5 X = X + 3;

P1 needs to add 2 to X

P2 needs to add 3 to X

P1 reads X (5)

P2 reads X (5)

P1 adds 2 to X and stores 7

P2 adds 3 to X and stores 8

Should X be 7, 8 or 10?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The order of the reads and writes affects the value stored.
P1 and P2 both read the same value of X(5) since the reads occur before the writes and value of X remains unchanged. P1 writes X as 7 but since P2 stores the value of X after P1, the value stored in X by P1 will be overwritten by P2 and 8 will be stored.
So, the final value in X is 8.

Add a comment
Know the answer?
Add Answer to:
P1 needs to add 2 to X P2 needs to add 3 to X P1 reads...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT