the meaning of volatile hans-j. boehm,. basic view of volatile/atomic if the only races involve...

3
The meaning of “volatile” Hans-J. Boehm,

Upload: luke-walton

Post on 26-Mar-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: The meaning of volatile Hans-J. Boehm,. Basic View of Volatile/Atomic If the only races involve synchronization variables (e.g. Java volatiles), then

The meaning of “volatile”

Hans-J. Boehm,

Page 2: The meaning of volatile Hans-J. Boehm,. Basic View of Volatile/Atomic If the only races involve synchronization variables (e.g. Java volatiles), then

Basic View of Volatile/Atomic

• If the only races involve synchronization variables (e.g. Java volatiles), then multithreaded execution can be viewed as interleaving:– “Dekker’s” example (everything initially zero):

Thread 1 Thread 2x = 1; y = 1;r1 = y; r2 = x;

– Might be executed as:x = 1; y = 1; r2 = x; r1 = y; orx = 1; y = 1; r1 = y; r2 = x;

– Outcome r1 = r2 = 0 is impossible• Java volatile, C++0x atomic<T> declare sync. variables.

*Provided certain esoteric library calls are avoided.

Page 3: The meaning of volatile Hans-J. Boehm,. Basic View of Volatile/Atomic If the only races involve synchronization variables (e.g. Java volatiles), then

Details across languages are confusing

Java volatile y y y n y n

C++0x SC (default) atomic<T> y y y n y y

C++0x low level atomic<T> n y y n s as

j.u.c.atomic def y y n def as

C + posix volatile n n n y m n

Java ordinary variables n y s n n n

C ordinary variables n n n n n n

def=“by default” as=“with alternate syntax” s=“sometimes” m=“maybe”

proh

ibits

r1

= r

2 =

0

proh

ibits

r1

= r

2 =

42

guar

ante

es

indi

visi

bilit

y

prev

ents

red

. lo

ad

elim

inat

ion

requ

ires

fenc

es f

or

X86

x++

is in

divi

sibl

e

Note: CLI omitted: in flux?