Question

assume I run this code in any language, may be in c, python or javascript etc on any computer, let assume on macbook-pro-late-2011 (that's the computer I have). What is the probability that I get an error if I run this code for infinite time.

    int a=1;
    int b=1;

    while(true)
    {
        if(a!=b){
          //error occurred
         }
    }

In simpler terms,

  1. How reliable are modern day processors ?
  2. Are there any processors from cheap brands that may often produce such errors, on devices like mobiles or tablets?
  3. Is there a famous case(from past) where modern day processors did produce wrong results?

Edit 1

Assuming machine would never die, overheat, bluescreen, or something.

No correct solution

OTHER TIPS

Yes, errors may occur in some non-zero probability, but are not likely to cause your program to reach the invalid condition check.

You may have alpha particles hitting some critical logic in your CPU or your memory at just the right moment to flip some bit (which may result in pretty much anything), or you could have some page swapped to a disk that has disfunctional segments. The exact rate at which this may occur depends on several things:

  1. The voltage levels your CPU uses - modern CPUs will have much lower levels to save power, mobile ones likely being some of the most sensitive at that. The lower the voltage, the lower the thresholds become, and it gets easier for some external force to flip the logical value.
  2. The environment in which you run - people designing CPUs for space shuttles, nuclear plants or even the CERN supercollider are probably working like hell to prevent this from happening, as these CPUs are probably constantly bombarded by radiation and seeing higher failure rates.
  3. Stress on the machine. A CPU working 24/7, is more likely to be hit.
  4. CPU area - servers with many cores are more likely to be hit, they simply pose a larger target.
  5. Built-in support for error detection and correction - most modern CPUs have ECC bits and parity checks in place for most of the sensitive HW areas. Single errors can usually be corrected, more complicated errors (several bits flipped) may be detected without the possibility to correct, but the HW would at least raise some fault or machine-check-error over this (so you won't even get to the error check in your code). For disk reliability you have another set of features of course, like RAID.

Note that some critical systems require higher level of reliability (banks, for e.g.), so they would likely buy CPUs offering better RAS features. Smartphones and tables are usually on the less critical part of the spectrum, but I guess you might see tables systems with some of this stuff.

Either way, any reasonable CPU today should have enough protection to capture most possible errors in high probability and fix in "under the hood", so you won't even know they existed. Complicated errors that can't be handled are still most likely to get caught, and would probably just cause your machine to hang or reboot. You can assume a simple program will have deterministic behavior with almost 100% probability.

So my two cents worth, (you are entitled to a full refund)

This is an easy to ask question but as soon as you look into it things get a bit murky.

If you define the question as specifically the case were a is not the same as b. In Python (as I understand it) a IS b and therefore will never fail. (This just says that if a changes, b will appear to change as well). Now turn the zoom knob out a bit. Now the '!=' part could fail for what ever reason and (still in python mind you) a IS still b. Is that a failure in the frame of your question?

Turn the zoom out a touch further, could the 'while True' fail? Is that even part of your question? Does the failure of the operating system count? Windows will reboot just cuz...

Then we get into Leeor's points.

As we keep zooming out, we keep finding cases that don't fit the question. If the data center where this is running is destroyed by EMP weapon wielding zombee's.... well you see where this is going.

In my past I have had to chase this very question down this path.(Medical, Avionics,...)

So then comes the circular "can we detect that there was a failure" (Leeor's point about ECC comes to mind). If it fails but we catch it, did it fail?

Quantum mechanics tells us that ultimately 'this_rock' != 'this_rock'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top