Skip to content

Data race in STM validation

While looking at !1603 (closed) I stumbled upon the following data race:

==================
WARNING: ThreadSanitizer: data race (pid=21811)
  Write of size 8 at 0x5580001e9820 by thread T6:
    #0 stmCommitTransaction rts/STM.c:1096 (T7815+0x000000750857)                                                                            
    #1 stg_atomically_frame_info <null> (T7815+0x00000079a913)
    #2 scheduleWorker rts/Schedule.c:2576 (T7815+0x000000758e28)                                                                             
    #3 workerStart rts/Task.c:445 (T7815+0x00000076399c)
    #4 <null> <null> (libtsan.so.0+0x000000028d5b)

  Previous read of size 8 at 0x5580001e9820 by thread T5:                                                                                    
    #0 validate_and_acquire_ownership rts/STM.c:771 (T7815+0x00000074f3d2)                                                                   
    #1 stmCommitTransaction rts/STM.c:1070 (T7815+0x000000750585)                                                                            
    #2 stg_atomically_frame_info <null> (T7815+0x00000079a913)                                                                               
    #3 scheduleWorker rts/Schedule.c:2576 (T7815+0x000000758e28)                                                                             
    #4 workerStart rts/Task.c:445 (T7815+0x00000076399c)                                                                                     
    #5 <null> <null> (libtsan.so.0+0x000000028d5b)                                                                                           
                                                                                                                                             
  Thread T6 (tid=21818, running) created by thread T4 at:                                                                                    
    #0 pthread_create <null> (libtsan.so.0+0x00000002c010)
    #1 createOSThread rts/posix/OSThreads.c:137 (T7815+0x000000794a48)                                                                       
    #2 startWorkerTask rts/Task.c:497 (T7815+0x000000763b71)
    #3 releaseCapability_ rts/Capability.c:567 (T7815+0x0000007407fd)                                                                        
    #4 suspendThread rts/Schedule.c:2424 (T7815+0x000000758435)                                                                              
    #5 <null> <null> (T7815+0x0000006a9769)
    #6 scheduleWorker rts/Schedule.c:2576 (T7815+0x000000758e28)                                                                             
    #7 workerStart rts/Task.c:445 (T7815+0x00000076399c)
    #8 <null> <null> (libtsan.so.0+0x000000028d5b)
    
  Thread T5 (tid=21817, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x00000002c010)
    #1 createOSThread rts/posix/OSThreads.c:137 (T7815+0x000000794a48)                                                                       
    #2 startWorkerTask rts/Task.c:497 (T7815+0x000000763b71)                                                                                 
    #3 releaseCapability_ rts/Capability.c:567 (T7815+0x0000007407fd)                                                                        
    #4 yieldCapability rts/Capability.c:927 (T7815+0x000000741b9a)                                                                           
    #5 scheduleYield rts/Schedule.c:681 (T7815+0x00000075412c)                                                                               
    #6 schedule rts/Schedule.c:295 (T7815+0x000000752b63)                                                                                    
    #7 scheduleWaitThread rts/Schedule.c:2559 (T7815+0x000000758a46)                                                                         
    #8 rts_evalLazyIO rts/RtsAPI.c:530 (T7815+0x0000007bb4eb)                                                                                
    #9 hs_main rts/RtsMain.c:72 (T7815+0x00000074b243)
    #10 main <null> (T7815+0x00000040857b)
    
SUMMARY: ThreadSanitizer: data race rts/STM.c:1096 in stmCommitTransaction                                             

validate_and_acquire_ownership reads StgTVar.num_updates but does not lock the TVar beforehand.

Edited by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information