DevLabs > DevLabs Forums > CHESS – Find and Reproduce Concurrency Heisenbugs > Is it possible to write a CHESS test that proves that reads and writes of 64-bit values are not atomic on 32-bit systems?
Ask a questionAsk a question
 

AnswerIs it possible to write a CHESS test that proves that reads and writes of 64-bit values are not atomic on 32-bit systems?

  • Friday, September 11, 2009 4:55 AMNeil_J Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is it possible to write a CHESS test that proves that reads and writes of 64-bit values are not atomic on 32-bit systems?

Answers

  • Friday, September 11, 2009 2:02 PMTom BallMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    At the MSIL level, I believe that a read/write of a 64-bit value is a single instruction. Since we instrument at the MSIL level, the answer would then be "no".

    -- Tom
  • Saturday, September 12, 2009 6:02 PMTom BallMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    The answer also is "no" because of the same reason above and the fact that CHESS serializes the execution of a multi-threaded program, which ends up having the effect of treating a read/write of a 64-bit value as atomic.  Now, with race detection turned on, CHESS will find that read/writes of longs (without any surrounding synchronization) have races, where it won't complain about interlocked operations. But same is true for 32-bit values.

    -- Tom

All Replies

  • Friday, September 11, 2009 2:02 PMTom BallMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    At the MSIL level, I believe that a read/write of a 64-bit value is a single instruction. Since we instrument at the MSIL level, the answer would then be "no".

    -- Tom
  • Saturday, September 12, 2009 1:21 AMNeil_J Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes you are right about the single instruction. I ran ildasm on "long l = 10L;" and "int i = 10;" and both compile to "ldc.i4.s 10" in MSIL.

    My next question is: Is it possible to write a CHESS test that fails because a long was read using "=" instead of Interlocked.Read()?
  • Saturday, September 12, 2009 6:02 PMTom BallMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    The answer also is "no" because of the same reason above and the fact that CHESS serializes the execution of a multi-threaded program, which ends up having the effect of treating a read/write of a 64-bit value as atomic.  Now, with race detection turned on, CHESS will find that read/writes of longs (without any surrounding synchronization) have races, where it won't complain about interlocked operations. But same is true for 32-bit values.

    -- Tom

  • Saturday, September 12, 2009 9:56 PMNeil_J Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Okay thanks Tom.