Understanding heisenbug example: different precision in registers vs main memory

后端 未结 3 751
一向
一向 2021-01-02 05:46

I read the wiki page about heisenbug, but don\'t understand this example. Can anyone explain it in detail?

One common example of a heisenbug is a bu

3条回答
  •  甜味超标
    2021-01-02 06:33

    It comes from Uncertainty Principle which basically states that there is a fundamental limit to the precision with which certain pairs of physical properties of a particle can be known simultaneously. If you start observing some particle too closely,(i.e., you know its position precisely) then you can't measure its momentum precisely. (And if you have precise speed, then you can't tell its exact position)

    So following this, Heisenbug is a bug which disappears when you are watching closely.

    In your example, if you need the program to perform well, you will compile it with optimization and there will be a bug. But as soon as you enter in debugging mode, you will not compile it with optimization which will remove the bug.

    So if you start observing the bug too closely, you will be uncertain to know its properties(or unable to find it), which resembles the Heisenberg's Uncertainty Principle and hence called Heisenbug.

提交回复
热议问题