FSL: A Program Logic for C11 Memory Fences Marko Doko Viktor - - PowerPoint PPT Presentation

fsl a program logic for c11 memory fences
SMART_READER_LITE
LIVE PREVIEW

FSL: A Program Logic for C11 Memory Fences Marko Doko Viktor - - PowerPoint PPT Presentation

FSL: A Program Logic for C11 Memory Fences Marko Doko Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) VMCAI 2016 Why C11? Oddities of weak memory W( ,0) W( ,0)


slide-1
SLIDE 1

FSL: A Program Logic for C11 Memory Fences

Marko Doko Viktor Vafeiadis

Max Planck Institute for Software Systems (MPI-SWS)

VMCAI 2016

slide-2
SLIDE 2

Why C11?

Oddities of weak memory

① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ ♣r✐♥t ②❀ ♣r✐♥t ①❀

W(①,0) W(②,0) W(①,1) R(②,0) W(②,1) R(①,0)

1

slide-3
SLIDE 3

Why C11?

Oddities of weak memory

① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ ♣r✐♥t ②❀ ♣r✐♥t ①❀

Both threads can print 0! W(①,0) W(②,0) W(①,1) R(②,0) W(②,1) R(①,0)

2

slide-4
SLIDE 4

Why C11?

Oddities of weak memory

① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ ♣r✐♥t ②❀ ♣r✐♥t ①❀

Both threads can print 0! W(①,0) W(②,0) W(①,1) R(②,0) W(②,1) R(①,0)

3

slide-5
SLIDE 5

Why C11?

Oddities of weak memory

① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ ♣r✐♥t ②❀ ♣r✐♥t ①❀

Both threads can print 0! W(①,0) W(②,0) W(①,1) R(②,0) W(②,1) R(①,0) sb sb sb sb sb

sb – sequenced-before

4

slide-6
SLIDE 6

Why C11?

Oddities of weak memory

① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ ♣r✐♥t ②❀ ♣r✐♥t ①❀

Both threads can print 0! W(①,0) W(②,0) W(①,1) R(②,0) W(②,1) R(①,0) sb sb sb sb sb rf rf

sb – sequenced-before rf – reads-from

5

slide-7
SLIDE 7

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

6

slide-8
SLIDE 8

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

7

slide-9
SLIDE 9

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race 8

slide-10
SLIDE 10

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

9

slide-11
SLIDE 11

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

race 10

slide-12
SLIDE 12

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

race

3

11

slide-13
SLIDE 13

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

race

3

rf 12

slide-14
SLIDE 14

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

race

3

rf sync 13

slide-15
SLIDE 15

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

race

3

rf sync

4

14

slide-16
SLIDE 16

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

race

3

rf sync

4

rf 15

slide-17
SLIDE 17

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

1

race

2

race

3

rf sync

4

rf sync 16

slide-18
SLIDE 18

C11 model through examples

✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

Why use fences? Release and acquire constructs are expensive!

17

slide-19
SLIDE 19

The synchronizes-with relation

Wrel Racq rf sync Wrel Facq R rf sb+ sync Frel Racq W rf sb+ sync Frel Facq W R rf sb+ sb+ sync

18

slide-20
SLIDE 20

The synchronizes-with relation

Wrel Racq rf sync RSL, GPS, OGRA Wrel Facq R rf sb+ sync Frel Racq W rf sb+ sync Frel Facq W R rf sb+ sb+ sync

RSL Relaxed Separation Logic (V. Vafeiadis, C. Narayan; OOPSLA ’13) GPS Ghosts, Protocols, and Separation (A. Turon, V. Vafeiadis, D. Dreyer; OOPSLA ’14) OGRA Owicki-Gries for Release-Acquire (O. Lahav, V. Vafeiadis; ICALP ’15)

19

slide-21
SLIDE 21

The synchronizes-with relation

Wrel Racq rf sync RSL , GPS, OGRA Wrel Facq R rf sb+ sync Frel Racq W rf sb+ sync Frel Facq W R rf sb+ sb+ sync

RSL Relaxed Separation Logic (V. Vafeiadis, C. Narayan; OOPSLA ’13) GPS Ghosts, Protocols, and Separation (A. Turon, V. Vafeiadis, D. Dreyer; OOPSLA ’14) OGRA Owicki-Gries for Release-Acquire (O. Lahav, V. Vafeiadis; ICALP ’15)

20

slide-22
SLIDE 22

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

Wrel Racq rf sync

21

slide-23
SLIDE 23

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

{true} ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

22

slide-24
SLIDE 24

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

{true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

23

slide-25
SLIDE 25

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

  • Q(v)
  • ❛t♦♠✐❝❴✐♥t ① ❂ v
  • Rel(x, Q) ∗ Acq(x, Q)
  • 24
slide-26
SLIDE 26

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

25

slide-27
SLIDE 27

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

26

slide-28
SLIDE 28

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} ⑥

  • Rel(x, Q) ∗ Q(v)
  • ①rel ❂ v
  • Rel(x, Q)
  • 27
slide-29
SLIDE 29

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} ⑥

28

slide-30
SLIDE 30

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} {&a → 42} ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} ⑥

  • Acq(x, Q)
  • t ❂ ①acq
  • Q(t)
  • 29
slide-31
SLIDE 31

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} {&a → 42} ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} {true} ⑥

30

slide-32
SLIDE 32

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} {&a → 42} ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} {true} ⑥ {true}

31

slide-33
SLIDE 33

Relaxed Separation Logic (RSL)

  • V. Vafeiadis, C. Narayan (OOPSLA 2013)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①acq ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} {&a → 42} ①rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} {true} ⑥ {true}

  • no data races
  • memory safety
  • no reads of uninitialized locations

32

slide-34
SLIDE 34

Fenced Separation Logic (FSL)

✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥

Frel Facq W R rf sb+ sb+ sync

33

slide-35
SLIDE 35

Fenced Separation Logic (FSL)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ {&a → 42} ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} {true} ⑥ {true}

Frel Facq W R rf sb+ sb+ sync ??? ???

34

slide-36
SLIDE 36

Fenced Separation Logic (FSL)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ {△(&a → 42) ∗ Rel(x, Q)} {&a → 42} ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} {true} ⑥ {true}

  • P
  • ❢❡♥❝❡rel
  • △P
  • Rel(x, Q) ∗ △Q(v)
  • ①rlx ❂ v
  • Rel(x, Q)
  • ???

35

slide-37
SLIDE 37

Fenced Separation Logic (FSL)

Q

def

= λv. (v = 0 ∨ &a → 42) {true} ✐♥t ❛ ❂ ✵❀ {&a → 0} ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ {&a → 0 ∗ Rel(x, Q) ∗ Acq(x, Q)} {&a → 0 ∗ Rel(x, Q)} {Acq(x, Q)} ❛ ❂ ✹✷❀ ✐❢✭①rlx ❂❂ ✶✮④ {&a → 42 ∗ Rel(x, Q)} {▽(&a → 42)} ❢❡♥❝❡rel❀ ❢❡♥❝❡acq❀ {△(&a → 42) ∗ Rel(x, Q)} {&a → 42} ①rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ {Rel(x, Q)} {true} {true} ⑥ {true}

  • Acq(x, Q)
  • t ❂ ①rlx

▽Q(t)

  • ▽P
  • ❢❡♥❝❡acq
  • P
  • 36
slide-38
SLIDE 38

Wrel Racq rf sync RSL, GPS, OGRA, FSL Wrel Facq R rf sb+ sync FSL Frel Racq W rf sb+ sync FSL Frel Facq W R rf sb+ sb+ sync FSL

37

slide-39
SLIDE 39

The semantics of triples

Without a notion of state, what is the meaning of

  • P
  • c
  • Q
  • ?

38

slide-40
SLIDE 40

The semantics of triples

Without a notion of state, what is the meaning of

  • P
  • c
  • Q
  • ?

Execution

  • f c

39

slide-41
SLIDE 41

The semantics of triples

Without a notion of state, what is the meaning of

  • P
  • c
  • Q
  • ?

Execution

  • f c

40

slide-42
SLIDE 42

The semantics of triples

Without a notion of state, what is the meaning of

  • P
  • c
  • Q
  • ?

Execution

  • f c

sb sb

41

slide-43
SLIDE 43

The semantics of triples

Without a notion of state, what is the meaning of

  • P
  • c
  • Q
  • ?

Execution

  • f c

sb sb Annotate heaps on sb and rf edges in the execution graph.

42

slide-44
SLIDE 44

The semantics of triples

Without a notion of state, what is the meaning of

  • P
  • c
  • Q
  • ?

Execution

  • f c

sb sb

h | = P

Annotate heaps on sb and rf edges in the execution graph.

43

slide-45
SLIDE 45

The semantics of triples

Without a notion of state, what is the meaning of

  • P
  • c
  • Q
  • ?

Execution

  • f c

sb sb

h | = P h′ | = Q

Annotate heaps on sb and rf edges in the execution graph.

44

slide-46
SLIDE 46

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

45

slide-47
SLIDE 47

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

Wrlx(①, 1)

46

slide-48
SLIDE 48

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

Wrlx(①, 1)

47

slide-49
SLIDE 49

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

Wrlx(①, 1)

48

slide-50
SLIDE 50

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

Wrlx(①, 1)

49

slide-51
SLIDE 51

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

Wrlx(①, 1)

△(&a → 42) ∗ Rel(x, Q)

50

slide-52
SLIDE 52

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

Wrlx(①, 1)

△(&a → 42) ∗ Rel(x, Q) Rel(x, Q)

51

slide-53
SLIDE 53

Local validity

a very simplified example

{△(&a → 42) ∗ Rel(x, Q)} ①rlx ❂ ✶ {Rel(x, Q)}

Wrlx(①, 1)

△(&a → 42) ∗ Rel(x, Q) Rel(x, Q) ▽(&a → 42)

52

slide-54
SLIDE 54

Independent heap compatibility

Definition (Independent edges) A set of edges T in an execution graph is pairwise independent if for all (a, a′), (b, b′) ∈ T , we have ¬(sb ∪ rf)∗(a′, b).

a a′ b b′ h1 h2 (sb ∪ rf)∗ = ⇒ h1 ⊕ h2 is defined

Lemma (Independent heap compatibility) For every validly annotated execution, and pairwise independent set of edges T , heaps annotated on edges in T are combinable.

53

slide-55
SLIDE 55

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+

54

slide-56
SLIDE 56

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) (sb ∪ sync)+

55

slide-57
SLIDE 57

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) (sb ∪ sync)+

56

slide-58
SLIDE 58

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) (sb ∪ rf)∗ (sb ∪ sync)+

57

slide-59
SLIDE 59

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − (sb ∪ sync)+

58

slide-60
SLIDE 60

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − ℓ → − (sb ∪ sync)+

59

slide-61
SLIDE 61

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − ℓ → − (sb ∪ sync)+

60

slide-62
SLIDE 62

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − ℓ → − (sb ∪ sync)+

61

slide-63
SLIDE 63

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − (sb ∪ rf)∗ (sb ∪ sync)+

62

slide-64
SLIDE 64

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − (sb ∪ rf)∗ (sb ∪ sync)+ sb sb (sb ∪ rf)∗

63

slide-65
SLIDE 65

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − (sb ∪ rf)∗ (sb ∪ sync)+ sb

  • sb
  • (sb ∪ rf)∗

{◦, △, ▽}

64

slide-66
SLIDE 66

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). ℓ → − access(ℓ) ℓ → − access(ℓ) ℓ → − (sb ∪ rf)∗ (sb ∪ sync)+ (sb ∪ sync)+ sb

  • sb
  • (sb ∪ rf)∗

{◦, △, ▽}

(sb ∪ sync)+

65

slide-67
SLIDE 67

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • 66
slide-68
SLIDE 68

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • 67
slide-69
SLIDE 69

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb

68

slide-70
SLIDE 70

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel

69

slide-71
SLIDE 71

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel sb

70

slide-72
SLIDE 72

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel sb

rf

W R

71

slide-73
SLIDE 73

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel sb

rf

W R sb

72

slide-74
SLIDE 74

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel sb

rf

W R sb

sb

  • Facq

73

slide-75
SLIDE 75

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel sb

rf

W R sb

sb

  • Facq

Frel Facq W R rf sb+ sb+ sync

74

slide-76
SLIDE 76

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel sb

rf

W R sb

sb

  • Facq

sync Frel Facq W R rf sb+ sb+ sync

75

slide-77
SLIDE 77

Data race freedom

Theorem In a validly annotated execution, any two non-atomic accesses to the same location are ordered by (sb ∪ sync)+ (i.e. they are not racing). (sb ∪ sync)+ sb

  • sb
  • sb
  • sb

Frel sb

rf

W R sb

sb

  • Facq

sync (sb ∪ sync)+ Frel Facq W R rf sb+ sb+ sync

76

slide-78
SLIDE 78

Summary and future work

Summary: FSL is the first logic that supports C11-style memory fences. FSL ensures

data race freedom, memory safety, and all reads read from initialized locations.

Soundness proof is formalized in Coq:

❤tt♣✿✴✴♣❧✈✳♠♣✐✲s✇s✳♦r❣✴❢s❧✴

Future work: Support for CAS instructions and fractional permissions. Verify real-world algorithms (such as Rust’s Arc).

77

slide-79
SLIDE 79
slide-80
SLIDE 80

Why the two modalities?

Q def = λv. if v = 0 then emp else a → 42

  • a → 0 ∗ Rel(x, Q)
  • ❛ ❂ ✹✷❀
  • a → 42 ∗ Rel(x, Q)
  • ❢❡♥❝❡rel❀
  • ♦a → 42 ∗ Rel(x, Q)
  • ①rlx ❂ ✶❀
  • true
  • Acq(x, Q)
  • ✇❤✐❧❡✭①rlx ❂❂ ✵✮❀
  • ♦a → 42
  • ②rlx ❂ ✶❀
  • true
  • Acq(y, Q)
  • ✇❤✐❧❡✭②rlx ❂❂ ✵✮❀
  • ♦a → 42
  • ❢❡♥❝❡acq❀
  • a → 42
  • ♣r✐♥t✭❛✮❀
  • a → 42
  • Wna(a, 42)

Frel Wrlx(x, 1) Rrlx(x, 1) Wrlx(y, 1) Rrlx(y, 1) Facq Rna(a, ?)

race

slide-81
SLIDE 81

Some important properties of FSL assertions

Release permissions are duplicable:

Rel(ℓ, Q) ⇐ ⇒ Rel(ℓ, Q) ∗ Rel(ℓ, Q)

Acquire permissions are splittable:

Acq(ℓ, Q1) ∗ Acq(ℓ, Q2) ⇐ ⇒ Acq(ℓ, λv. Q1(v) ∗ Q2(v))

Modalities (△ and ▽) distribute over disjunction, conjunction, and separating conjunction:

△(P ∧ Q) ⇐ ⇒ △P ∧ △Q ▽(P ∧ Q) ⇐ ⇒ ▽P ∧ ▽Q △(P ∨ Q) ⇐ ⇒ △P ∨ △Q ▽(P ∨ Q) ⇐ ⇒ ▽P ∨ ▽Q △(P ∗ Q) ⇐ ⇒ △P ∗ △Q ▽(P ∗ Q) ⇐ ⇒ ▽P ∗ ▽Q