Dynamic data race prediction (Tutorial)

Bas van den Heuvel

2024-05-10

Summary

See lecture notes.

Valid Trace Reorderings

In the literature referred to as Correct Trace Reordering.

Two requirements:

Well-formedness

We often omit forkfork events, assuming all threads are initially forked by the main thread.

HB additionally requires:

Program-order and Last-writer Conditions

We have seen:

Examples

HB, ESs, and Set-based Race Predictor.

Example 1

     T1            T2            ES
              
e1.   fork(T2)                    
e2.   wr(x)                       
e3.   rd(x)                       
e4.                 rd(x)         
e5.                 wr(x)         

HB: 1<2<31 < 2 < 3 and 1<4<51 < 4 < 5.

     T1            T2            ES            
                                               
e1.   fork(T2)                    {1}              
e2.   wr(x)                       {1,2}              
e3.   rd(x)                       {1,2,3}              
e4.                 rd(x)         {1,4}
e5.                 wr(x)         {1,4,5}

Example 2

     T1            T2            ES            
                                               
e1.   fork(T2)                                  
e2.   wr(x)                                     
e3.   wr(y)                                     
e4.                 rd(y)                       
e5.                 wr(x)                       

HB: 1<2<31<2<3 and 1,4,51,4,5.

     T1            T2            ES                       
                                                            
e1.   fork(T2)                    {1}         D(T1) = {1} ; D(T2) = {1}        
e2.   wr(x)                       {1,2}       D(T1) = {1,2} ; W(x) = 2         
e3.   wr(y)                       {1,2,3}     D(T1) = {1,2,3} ; W(y) = 3         
e4.                 rd(y)         {1,4}       W(y) notin D(T2) ; R(y) = {4} ; D(T2) = {1,4}        
e5.                 wr(x)         {1,4,5}     W(x) notin D(T2) ; D(T2) = {1,4,5} ; W(x) = 5         

Example 3

     T1            T2          ES             
                                            
e1.   fork(T2)                                 
e2.   wr(a)                                    
e3.   acq(x)                                   
e4.   wr(b)                                    
e5.   rel(x)                                   
e6.   wr(c)                                 
e7.                 acq(x)                     
e8.                 rd(a)                      
e9.                 rd(b)                      
e10.                rel(x)                     
e11.                wr(c)                      

HB: 1<2<3<4<5<61<2<3<4<5<6, 1<7,8,9,10,111<7,8,9,10,11, and 5<75<7.

     T1            T2          ES                        
                                                         
e1.   fork(T2)                  {1}                     D(T1) = {1} ; D(T2) = {1}        
e2.   wr(a)                     {1,2}                   D(T1) = {1,2} ; W(a) = 2          
e3.   acq(x)                    {1,2,3}                 D(T1) = {1,2,3}            
e4.   wr(b)                     {1,2,3,4}               D(T1) = {1,2,3,4} ; W(b) = 4              
e5.   rel(x)                    {1,2,3,4,5}             D(T1) = {1,2,3,4,5} ; Rel(x) = {1,2,3,4,5}                
e6.   wr(c)                     {1,2,3,4,5,6}           D(T1) = {1,2,3,4,5,6} ; W(c) = 6               
e7.                 acq(x)      {1,2,3,4,5,7}           D(T2) = {1,2,3,4,5,7}     
e8.                 rd(a)       {1,2,3,4,5,7,8}         R(a) = {8} ; D(T2) = {1,2,3,4,5,7,8}       
e9.                 rd(b)       {1,2,3,4,5,7,8,9}       R(b) = {9} ; D(T2) = {1,2,3,4,5,7,8,9}         
e10.                rel(x)      {1,2,3,4,5,7,8,9,10}    D(T2) = {1,2,3,4,5,7,8,9,10} ; Rel(x) = {1,2,3,4,5,7,8,9,10}            
e11.                wr(c)       {1,2,3,4,5,7,8,9,10,11} W(c) notin D(T2) ; D(T2) = {1,2,3,4,5,7,8,9,10,11} ; W(c) = 11               

Example 4

     T1            T2                        
              
e1.   fork(T2)               
e2.   acq(x)                 
e3.   wr(a)                  
e4.   rel(x)                 
e5.                 acq(x)   
e6.                 rd(a)    
e7.                 rel(x)       

HB: 1<2<3<41<2<3<4, 1<5<6<71<5<6<7, and 4<54<5.

     T1            T2                        
              
e1.   fork(T2)               D(T1) = {1} ; D(T2) = {1}                   
e2.   acq(x)                 D(T1) = {1,2}     
e3.   wr(a)                  D(T1) = {1,2,3} ; W(a) = 3     
e4.   rel(x)                 D(T1) = {1,2,3,4} ; Rel(x) = {1,2,3,4}     
e5.                 acq(x)   D(T2) = {1,2,3,4,5}     
e6.                 rd(a)    D(T2) = {1,2,3,4,5,6} ; W(a) = 6     
e7.                 rel(x)   D(T2) = {1,2,3,4,5,6,7} ; Rel(x) = {1,2,3,4,5,6,7}     

Example 5

     T1            T2            
              
e1.   fork(T2)                    
e2.   acq(l)                      
e3.   wr(x)                       
e4.   rel(l)                      
e5.                 acq(l)        
e6.                 wr(x)         
e7.                 rel(l)        
e8.                 rd(x)         

HB: 1<2<3<41<2<3<4, 1<5<6<7<81<5<6<7<8, and 4<54<5.

Correct reordering with a data race:

     T0            T1            
              
e1.   fork(T1)                    
e5.                 acq(l)        
e6.                 wr(x)         
e7.                 rel(l)        
e2.   acq(l)                      
e8.                 rd(x)         
e3.   wr(x)                       
e4.   rel(l)                      

Example 6

     T1            T2            T3            
              
e1.   fork(T3)                                  
e2.   acq(l)                                    
e3.   fork(T2)                                  
e4.                 wr(x)                       
e5.   join(T2)                                  
e6.   rel(l)                                    
e7.                               acq(l)        
e8.                               wr(x)         
e9.                               rel(l)        
e10.                              rd(x)         

HB: 1<2<3<5<61<2<3<5<6, 3<4<53<4<5, 1<7<8<9<101<7<8<9<10, and 6<76<7.

Correct reordering with a data race: ~~~ T0 T1 T2

e1. fork(T2)
e7. acq(l)
e8. wr(x)
e9. rel(l)
e2. acq(l)
e3. fork(T1)
e10. rd(x)
e4. wr(x)
e5. join(T1)
e6. rel(l)
~~~