Question: Assuming the Java memory model, (a) Explain why it is not sufficient in Figure 13.11 to label X and Y as volatile. (b) Explain why

Assuming the Java memory model,

(a) Explain why it is not sufficient in Figure 13.11 to label X and Y as volatile.

(b) Explain why it is sufficient, in that same figure, to enclose C’s reads (and similarly those of D) in a synchronized block for some common shared object O.

(c) Explain why it is sufficient, in Example 13.31, to label both inspected and X as volatile, but not to label only one.

Figure 13.11:

Initially: X = Y = 0 Core A: Core B: X:= 1 Y:= 1 Core C: Core D: cx := X dy := Y cy := Y dx := X

Initially: X = Y = 0 Core A: Core B: X:= 1 Y:= 1 Core C: Core D: cx := X dy := Y cy := Y dx := X

Step by Step Solution

3.42 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a Labeling a variable volatile in Java ensures that a read of it is ordered before any subsequent op... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Language Pragmatics Questions!