Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: replaced table with graphic

...

Consider two threads that are executing some statements:

...

Thread 1

...

Statement 1

...

(statement does not use a volatile variable)

...

Statement 2

...

(statement does not use a volatile variable)

...

Statement 3

...

(statement is a write to a volatile variable v)

...

 

...

 

...

Thread 2

...

 

...

 

...

Statement 4

...

Image Added

Thread 1 and Thread 2 have a happens-before relationship such that Thread 2 does not start before Thread 1 finishes. This is established by the semantics of volatile accesses. Sequential consistency of volatile accesses provides certain visibility and reordering guarantees:

...