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) ① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ W( ① ,1) W( ② ,1) ♣r✐♥t ②❀ ♣r✐♥t ①❀ R( ② ,0) R( ① ,0) 1
Why C11? Oddities of weak memory W( ① ,0) W( ② ,0) ① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ W( ① ,1) W( ② ,1) ♣r✐♥t ②❀ ♣r✐♥t ①❀ Both threads can print 0! R( ② ,0) R( ① ,0) 2
Why C11? Oddities of weak memory W( ① ,0) W( ② ,0) ① ❂ ✵❀ ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ W( ① ,1) W( ② ,1) ♣r✐♥t ②❀ ♣r✐♥t ①❀ Both threads can print 0! R( ② ,0) R( ① ,0) 3
Why C11? Oddities of weak memory W( ① ,0) sb W( ② ,0) ① ❂ ✵❀ sb sb ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ W( ① ,1) W( ② ,1) ♣r✐♥t ②❀ ♣r✐♥t ①❀ sb sb Both threads can print 0! R( ② ,0) R( ① ,0) sb – sequenced-before 4
Why C11? Oddities of weak memory W( ① ,0) sb W( ② ,0) ① ❂ ✵❀ sb sb rf ② ❂ ✵❀ ① ❂ ✶❀ ② ❂ ✶❀ W( ① ,1) W( ② ,1) ♣r✐♥t ②❀ ♣r✐♥t ①❀ rf sb sb Both threads can print 0! R( ② ,0) R( ① ,0) sb – sequenced-before rf – reads-from 5
✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ⑥ ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ⑥ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples 6
✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ⑥ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples ✐♥t ❛ ❂ ✵❀ 1 ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ 7
✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ⑥ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples ✐♥t ❛ ❂ ✵❀ 1 ✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ race ⑥ 8
✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ⑥ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race ⑥ ⑥ 9
✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ⑥ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race race ⑥ ⑥ 10
✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race race ⑥ ⑥ 3 ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① acq ❂❂ ✶✮④ ① rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ 11
✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race race ⑥ ⑥ 3 ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① acq ❂❂ ✶✮④ rf ① rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ 12
✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❢❡♥❝❡ ❀ ❢❡♥❝❡ ❀ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race race ⑥ ⑥ 3 ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① acq ❂❂ ✶✮④ rf ① rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ sync ⑥ 13
C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race race ⑥ ⑥ 3 ✐♥t ❛ ❂ ✵❀ 4 ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① acq ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ rf ① rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ rel ❀ ❢❡♥❝❡ acq ❀ sync ⑥ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ 14
C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race race ⑥ ⑥ 3 ✐♥t ❛ ❂ ✵❀ 4 ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① acq ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ rf ① rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ rel ❀ rf ❢❡♥❝❡ acq ❀ sync ⑥ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ 15
C11 model through examples ✐♥t ❛ ❂ ✵❀ ✐♥t ❛ ❂ ✵❀ 1 2 ✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ ① ❂ ✶❀ ♣r✐♥t✭❛✮❀ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ race race ⑥ ⑥ 3 ✐♥t ❛ ❂ ✵❀ 4 ✐♥t ❛ ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛t♦♠✐❝❴✐♥t ① ❂ ✵❀ ❛ ❂ ✹✷❀ ✐❢✭① acq ❂❂ ✶✮④ ❛ ❂ ✹✷❀ ✐❢✭① rlx ❂❂ ✶✮④ rf ① rel ❂ ✶❀ ♣r✐♥t✭❛✮❀ ❢❡♥❝❡ rel ❀ rf ❢❡♥❝❡ acq ❀ sync sync ⑥ ① rlx ❂ ✶❀ ♣r✐♥t✭❛✮❀ ⑥ 16
Recommend
More recommend