![Page 1: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/1.jpg)
A Promising Semantics forRelaxed-Memory Concurrency
Jeehoon KangChung-Kil Hur
Seoul National University(Korea)
Ori LahavViktor VafeiadisDerek Dreyer
MPI-SWS(Germany)
May 2017Shonan Meeting
![Page 2: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/2.jpg)
/28
A Message Passing Example:
No Data Race
D = 42
LOCK(L)
F = 1
UNLOCK(L)
while (1) {
LOCK(L)
f = F
UNLOCK(L)
if (f) break
}
d = D
Initially: D = F = 0
Finally: d = 42
2
![Page 3: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/3.jpg)
/28
Sequentially Consistent Concurrency
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
Initially: D = F = 0
Finally: d = 42
3
![Page 4: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/4.jpg)
/28
Relaxed-Memory Concurrency
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
Initially: D = F = 0
Finally: d = 42 or 0
F = 1
D = 42
HW out of order exec
4
![Page 5: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/5.jpg)
/28
Release & Acquire
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
Initially: D = F = 0
Finally: d = 42
[rel]
[acq]
5
![Page 6: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/6.jpg)
/28
Release & Acquire
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
Initially: D = F = 0
Finally: d = 42
[rel]
[acq]
Run as if in a single thread
5
![Page 7: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/7.jpg)
/28
Release & Acquire with Tweak
D = 42
F = 1
f = F
if (f) {
d = D // d = 42?
}
D = 10
Initially: D = F = 0
[rel]
[acq]
6
![Page 8: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/8.jpg)
/28
Concurrency Models
• Semantics of multi-threaded programs?
- Sequential consistency (SC): simple but expensive
• Relaxed memory model (C/C++, Java)
- Many consistency modes (cost vs. consistency tradeoff)
- Open problem: what is the “right” semantics?
7
![Page 9: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/9.jpg)
/28
“Right” Concurrency Semantics?
Conflicting goals of compilers, hardware &programmers
• Compiler/hardware: validating optimizations(e.g. reordering, merging)
• Programmer: supporting reasoning principles(e.g. DRF theorem, program logic)
8
![Page 10: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/10.jpg)
/28
“Right” Concurrency Semantics?
Conflicting goals of compilers, hardware &programmers
• Compiler/hardware: validating optimizations(e.g. reordering, merging)
• Programmer: supporting reasoning principles(e.g. DRF theorem, program logic)
Java memory model
8
![Page 11: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/11.jpg)
/28
“Right” Concurrency Semantics?
Conflicting goals of compilers, hardware &programmers
• Compiler/hardware: validating optimizations(e.g. reordering, merging)
• Programmer: supporting reasoning principles(e.g. DRF theorem, program logic)
Java memory model
C/C++ memory model
8
![Page 12: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/12.jpg)
/28
“Right” Concurrency Semantics?
Conflicting goals of compilers, hardware &programmers
• Compiler/hardware: validating optimizations(e.g. reordering, merging)
• Programmer: supporting reasoning principles(e.g. DRF theorem, program logic)
Java memory model
C/C++ memory model
8
![Page 13: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/13.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
9
![Page 14: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/14.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
Registers
9
![Page 15: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/15.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
RegistersShared
Locations
9
![Page 16: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/16.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
RegistersShared
Locations
C11Relaxed
9
![Page 17: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/17.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
9
![Page 18: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/18.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
X = 42b = Y
9
![Page 19: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/19.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
X = 42b = Y
Read X,42
Write Y,42
Read Y,42
Write X,42
(X=Y=0)
(read-from)
(sequenced-before)
9
![Page 20: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/20.jpg)
/28
“Out-of-thin-air” problem (1/3)
Load-Buffering (LB)
a = XY = a
b = YX = 42
Thread 1 Thread 2
(allowed: a=b=42)
X = 42b = Y
Read X,42
Write Y,42
Read Y,42
Write X,42
(X=Y=0)
(read-from)
(sequenced-before)
Justification is too loose!
9
![Page 21: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/21.jpg)
/28
“Out-of-thin-air” problem (2/3)
Classical Out-of-thin-air (OOTA)
a = XY = a
b = YX = b
Thread 1 Thread 2
(forbidden: a=b=42)
10
![Page 22: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/22.jpg)
/28
“Out-of-thin-air” problem (2/3)
Classical Out-of-thin-air (OOTA)
a = XY = a
b = YX = b
Thread 1 Thread 2
(forbidden: a=b=42)
Reasoning principles(e.g. invariant a=b=X=Y=0)
10
![Page 23: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/23.jpg)
/28
“Out-of-thin-air” problem (2/3)
Classical Out-of-thin-air (OOTA)
a = XY = a
b = YX = b
Thread 1 Thread 2
(forbidden: a=b=42)
Reasoning principles(e.g. invariant a=b=X=Y=0)
Read X,42
Write Y,42
Read Y,42
Write X,42
(X=Y=0)
(read-from)
(sequenced-before)
10
![Page 24: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/24.jpg)
/28
“Out-of-thin-air” problem (2/3)
Classical Out-of-thin-air (OOTA)
a = XY = a
b = YX = b
Thread 1 Thread 2
(forbidden: a=b=42)
Reasoning principles(e.g. invariant a=b=X=Y=0)
Read X,42
Write Y,42
Read Y,42
Write X,42
(X=Y=0)
(read-from)
(sequenced-before)
What does hardware do?
10
![Page 25: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/25.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
11
a = XY = a
b = YX = 42
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
![Page 26: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/26.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
11
a = XY = a
b = YX = 42
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
(dep)
![Page 27: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/27.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
11
a = XY = a
b = YX = 42
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
(dep)
![Page 28: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/28.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
12
a = XY = a
b = YX = b+42-b
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
(dep)
![Page 29: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/29.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
12
a = XY = a
b = YX = b+42-b
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
(dep)
![Page 30: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/30.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
12
a = XY = a
b = YX = b+42-b
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
(dep)
![Page 31: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/31.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
12
a = XY = a
b = YX = b+42-b
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
(dep)
![Page 32: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/32.jpg)
/28
“Out-of-thin-air” problem (3/3)
Tracking Syntactic Dependency?
12
a = XY = a
b = YX = b+42-b
Thread 1 Thread 2
(a=b=42?)
a = XY = a
b = YX = b
Thread 1 Thread 2
(a=b=42?)
(dep)
![Page 33: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/33.jpg)
/28
Promising Semantics
• Solving the out-of-thin-air problem
• Supporting optimizations & reasoning principles
• Covering most C/C++ concurrency features
• Operational semantics w/o undefined behavior
• Most results are verified in Coq
http://sf.snu.ac.kr/promise-concurrency
13
![Page 34: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/34.jpg)
/28
Key Idea 1: Messages & Views
• Memory: pool of messages (loc, val, timestamp)
• Per-thread view on the memory
14
Timestamp
Loc.
X
Y
0
0 37
85
42
42
![Page 35: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/35.jpg)
/28
Thread 1
Key Idea 1: Messages & Views
• Memory: pool of messages (loc, val, timestamp)
• Per-thread view on the memory
14
Timestamp
Loc.
X
Y
0
0 37
85
42
42
![Page 36: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/36.jpg)
/28
readable/writable
Thread 1
Key Idea 1: Messages & Views
• Memory: pool of messages (loc, val, timestamp)
• Per-thread view on the memory
14
Timestamp
Loc.
X
Y
0
0 37
85
42
42
![Page 37: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/37.jpg)
/28
readable/writable
Thread 1 Thread 2
Key Idea 1: Messages & Views
• Memory: pool of messages (loc, val, timestamp)
• Per-thread view on the memory
14
Timestamp
Loc.
X
Y
0
0 37
85
42
42
![Page 38: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/38.jpg)
/28
Example
Store Buffering
Y = 42 a = X
X = 42b = Y
Timestamp
Loc.
X
Y
0
0
(allowed: a=b=0)Thread 1 Thread 2
15
![Page 39: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/39.jpg)
/28
Example
Store Buffering
Y = 42 a = X
X = 42b = Y
Timestamp
Loc.
X
Y
0
0
(allowed: a=b=0)Thread 1 Thread 2
b = Y X = 42reorderable
(x86/Power/ARM)
15
![Page 40: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/40.jpg)
/28
Example
Store Buffering
Y = 42 a = X
X = 42b = Y
Timestamp
Loc.
X
Y
0
0 42
(allowed: a=b=0)Thread 1 Thread 2
b = Y X = 42reorderable
(x86/Power/ARM)
15
![Page 41: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/41.jpg)
/28
Example
Store Buffering
Y = 42 a = X
X = 42b = Y
Timestamp
Loc.
X
Y
0
0
42
42
(allowed: a=b=0)Thread 1 Thread 2
b = Y X = 42reorderable
(x86/Power/ARM)
15
![Page 42: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/42.jpg)
/28
Example
Store Buffering
Y = 42 a = X
X = 42b = Y
Timestamp
Loc.
X
Y
0
0
42
42
(allowed: a=b=0)Thread 1 Thread 2
b = Y X = 42reorderable
(x86/Power/ARM)
15
![Page 43: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/43.jpg)
/28
Example
Store Buffering
Y = 42 a = X
X = 42b = Y
Timestamp
Loc.
X
Y
0
0
42
42
(allowed: a=b=0)Thread 1 Thread 2
b = Y X = 42reorderable
(x86/Power/ARM)
15
![Page 44: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/44.jpg)
/28
Example
Load Buffering (LB)
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2 (allowed: a=b=42)
16
![Page 45: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/45.jpg)
/28
Key Idea 2: Promises
• A thread can promise to write X=V in the future,after which other threads can read X=V.
• To avoid OOTA, the promising thread mustcertify that it can write X=V in isolation.
• Until all its promises are fulfilled, the thread can take certifiable steps only.
17
![Page 46: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/46.jpg)
/28
Example
Load Buffering (LB)
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2 (allowed: a=b=42)
18
![Page 47: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/47.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2 (allowed: a=b=42)
Thread 2’spromise
18
![Page 48: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/48.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2 (allowed: a=b=42)
Thread 2’spromise
18
![Page 49: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/49.jpg)
/28
Example
Certification
42
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 2
Thread 2’spromise
19
![Page 50: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/50.jpg)
/28
Example
Certification
42
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 2
Thread 2’spromise
19
![Page 51: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/51.jpg)
/28
Example
Certification
42
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 2
42
Thread 2’spromise
19
![Page 52: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/52.jpg)
/28
Example
Certification
42
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 2
42
Thread 2’spromise
19
![Page 53: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/53.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2
Thread 2’spromise
(allowed: a=b=42)
20
![Page 54: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/54.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2
Thread 2’spromise
(allowed: a=b=42)
20
![Page 55: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/55.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0 42
Thread 1 Thread 2
Thread 2’spromise
(allowed: a=b=42)
20
![Page 56: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/56.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0 42
Thread 1 Thread 2
Thread 2’spromise
(allowed: a=b=42)
20
![Page 57: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/57.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
42
42
Thread 1 Thread 2
Thread 2’spromise
(allowed: a=b=42)
20
![Page 58: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/58.jpg)
/28
Example
Load Buffering (LB)
42
a = XY = a
b = YX = 42
Timestamp
Loc.
X
Y
0
0
42
42
Thread 1 Thread 2
Thread 2’spromise
b = YX = b+42-b
(allowed: a=b=42)
20
![Page 59: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/59.jpg)
/28
Example
Classical Out-of-thin-air (OOTA)
a = X Y = a
b = YX = b
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2(forbidden: a=b=42)
21
![Page 60: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/60.jpg)
/28
Example
Classical Out-of-thin-air (OOTA)
42
a = X Y = a
b = YX = b
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2(forbidden: a=b=42)
Thread 2’spromise?
21
![Page 61: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/61.jpg)
/28
Example
Classical Out-of-thin-air (OOTA)
42
a = X Y = a
b = YX = b
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2(forbidden: a=b=42)
Thread 2’spromise?
21
![Page 62: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/62.jpg)
/28
Example
Classical Out-of-thin-air (OOTA)
42
a = X Y = a
b = YX = b
Timestamp
Loc.
X
Y
0
0
Thread 1 Thread 2(forbidden: a=b=42)
Thread 2’spromise?
21
![Page 63: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/63.jpg)
/28
The Message Passing Example
22
Timestamp
Loc.
D
F
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0
![Page 64: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/64.jpg)
/28
The Message Passing Example
22
Timestamp
Loc.
D
F
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0
42
![Page 65: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/65.jpg)
/28
The Message Passing Example
22
Timestamp
Loc.
D
F
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0
42
1
![Page 66: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/66.jpg)
/28
The Message Passing Example
22
Timestamp
Loc.
D
F
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0
42
1
![Page 67: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/67.jpg)
/28
The Message Passing Example
22
Timestamp
Loc.
D
F
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0
42
1
d = 0
![Page 68: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/68.jpg)
/28
Timestamp
Loc.
D
F
Release & Acquire
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0
[rel] [acq]
23
![Page 69: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/69.jpg)
/28
Timestamp
Loc.
D
F
Release & Acquire
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0
42
[rel] [acq]
23
![Page 70: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/70.jpg)
/28
Timestamp
Loc.
D
F
Release & Acquire
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0 1
42
[rel] [acq]
23
![Page 71: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/71.jpg)
/28
Timestamp
Loc.
D
F
Release & Acquire
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0 released at1
42
[rel] [acq]
23
![Page 72: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/72.jpg)
/28
Timestamp
Loc.
D
F
Release & Acquire
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0 released at1
42
[rel] [acq]
23
![Page 73: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/73.jpg)
/28
Timestamp
Loc.
D
F
Release & Acquire
Thread 1 Thread 2
D = 42
F = 1
while (1) {
f = F
if (f) break
}
d = D
0
0 released at1
42
[rel] [acq]
d = 42
23
![Page 74: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/74.jpg)
/28
Release & Acquire with Tweak
D = 42
F = 1
f = F
if (f) {
d = D // d = 42?
}
D = 10
Initially: D = F = 0
[rel]
[acq]
24
![Page 75: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/75.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
25
![Page 76: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/76.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
25
![Page 77: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/77.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
25
![Page 78: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/78.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
25
![Page 79: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/79.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
25
![Page 80: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/80.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
25
![Page 81: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/81.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
25
![Page 82: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/82.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
Z=1 fulfilled
25
![Page 83: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/83.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
25
![Page 84: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/84.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
25
![Page 85: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/85.jpg)
/28
[acq]
[acq][acq]
[rel] [rel][rel]
Re-Certification is Necessary
• A thread must re-certify during the executionthat it can write all its promises in isolation.
W=1 if (W) Y=1else Z=1
if (X) Z=1
Thread 1 Thread 2
(forbidden: X=1)
if (Y && Z) X=1
Thread 3
Z=1 promised
Certified:T2 in isolation
Re-certification:Failed!
Because X = 0
25
![Page 86: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/86.jpg)
Example
Counter
26
Core 1 Core 2
r1 = fetch-add X
(forbidden: r1=1,r2=1)
r2 = fetch-add X
Timestamp
Loc.
X 0
![Page 87: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/87.jpg)
Example
Counter
26
Core 1 Core 2
r1 = fetch-add X
(forbidden: r1=1,r2=1)
r2 = fetch-add X
Timestamp
Loc.
X 0 1
![Page 88: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/88.jpg)
Example
Counter
26
Core 1 Core 2
r1 = fetch-add X
(forbidden: r1=1,r2=1)
r2 = fetch-add X
Timestamp
Loc.
X 0 1 2
![Page 89: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/89.jpg)
/28
Example
Write-Read Coherence
X = 1a = X
X = 2b = X
(forbidden: a=2,b=1)Thread 1 Thread 2
27
![Page 90: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/90.jpg)
/28
Example
Write-Read Coherence
X = 1a = X
X = 2b = X
(forbidden: a=2,b=1)Thread 1 Thread 2
27
![Page 91: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/91.jpg)
/28
Example
Write-Read Coherence
X = 1a = X
X = 2b = X
(forbidden: a=2,b=1)Thread 1 Thread 2
27
![Page 92: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/92.jpg)
/28
Example
Write-Read Coherence
X = 1a = X
X = 2b = X
(forbidden: a=2,b=1)Thread 1 Thread 2
27
![Page 93: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/93.jpg)
/28
Example
Write-Read Coherence
X = 1a = X
X = 2b = X
(forbidden: a=2,b=1)Thread 1 Thread 2
27
![Page 94: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/94.jpg)
/28
Example
Read-Write Coherence
X = 1X = 2
a = Xb = X
Thread 1 Thread 2 (forbidden: a=2,b=1)
28
![Page 95: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/95.jpg)
/28
Example
Read-Write Coherence
X = 1X = 2
a = Xb = X
Thread 1 Thread 2 (forbidden: a=2,b=1)
28
![Page 96: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/96.jpg)
/28
Example
Read-Write Coherence
X = 1X = 2
a = Xb = X
Thread 1 Thread 2 (forbidden: a=2,b=1)
28
![Page 97: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/97.jpg)
/28
Example
Read-Write Coherence
X = 1X = 2
a = Xb = X
Thread 1 Thread 2 (forbidden: a=2,b=1)
28
![Page 98: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/98.jpg)
/28
Example
Read-Write Coherence
X = 1X = 2
a = Xb = X
Thread 1 Thread 2 (forbidden: a=2,b=1)
28
![Page 99: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/99.jpg)
/28
Results (1/2)
Compiler/HW Optimizations
• Operational semantics for C/C++ concurrency:plain/relaxed/release/acquire r/w/u/fence, SC fence
• Compiler optimizations(reordering, merge, dead load elim., …)
• Compilation to x86 & Power
29
![Page 100: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/100.jpg)
/28
Results (2/2)
Reasoning Principles
• DRF-SC: Data Race Freedom ⇒ SC
- DRF-PromiseFree: DRF ⇒ semantics w/o promises
• Invariant-based logic:soundness of global invariant (e.g. a=b=X=Y=0)
• http://sf.snu.ac.kr/promise-concurrency
30
![Page 101: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/101.jpg)
/28
Results (2/2)
Reasoning Principles
• DRF-SC: Data Race Freedom ⇒ SC
- DRF-PromiseFree: DRF ⇒ semantics w/o promises
• Invariant-based logic:soundness of global invariant (e.g. a=b=X=Y=0)
• http://sf.snu.ac.kr/promise-concurrency
30
![Page 102: A Promising Semantics for Relaxed-Memory Concurrency · 2018-08-17 · A thread can promise to write X=V in the future, after which other threads can read X=V. • To avoid OOTA,](https://reader036.vdocument.in/reader036/viewer/2022070719/5edf6aadad6a402d666ac3c2/html5/thumbnails/102.jpg)
/28
Future Work
• Supporting SC reads & writes(We found a flaw in C/C++11 on SC)
• Supporting consume reads
• Developing a rich program logic &Verifying fine-grained concurrent programs
31