On 8/3/2012 2:49 AM, Jorgen Grahn wrote:
> On Fri, 2012-08-03, Stuart wrote:
> ...
>> Actually, I'm relying heavily on the stack unwind, since this
>> constitutes a kind of emergency stop procedure for me. The only
>> alternative would be to create a separate stack with emergency stop
>> actions that should be executed when an Access Violation occurs, but
>> that would be equally cumbersome.
> ...
>> So let me rephrase it: Ideally, I would like the language to dump when
>> an Access Violation occurs (gives me all the information to debug the
>> programming error later on), and then to unwind the stack (brings the
>> measurement machine back into a defined state).
>
> There's possibly one non-C++ mechanism at play here.
>
> If you're into controlling hardware (or other I/O not heavily
> encapsulated by the OS) you often have OS mechanisms as a last resort.
>
> E.g. if you control a flatbed scanner you want the light to go off and
> the camera arm to move back to its parked position. A well-designed
> device driver for that will see its file descriptor (in Unix) close as
> the application crashes, and reset itself. Placing responsibility for
> the reset on the application would be a very bad idea. Even if you
> changed C++ so you could reliably do that before crashing, the device
> could still not be safely used from C, Python, Perl, ...
>
yeah. it also makes sense to try to design software so that it can
recover from crashes.
usually, this often means explicit recover mechanisms, say the app can
fix its data once it restarts, and generally avoid leaving data in a
state where it will be "dead in the water" if a crash occurs.
drivers can often help here.
likewise, even a lot of hardware itself has its own safety mechanisms,
usually in the form of on-device firmware, and sometimes via
electromechanical mechanisms or similar, such as in the case of HDDs and
similar (for example, if an HDD looses power, it will automatically park
the heads, ...).
sadly, OS filesystem drivers and similar are often not as robustly
designed, as damage in the right spot may often render the drive unable
to recover (say, damage to the partition table / MBR, corruption of the
boot-sector or other core filesystem structures, ...).
things like journals/... can help, but usually performance and low
overhead are preferred over robustness, which is often left over to the
HDD (which itself is left implementing things like ECC and
sector-remapping, ..., at some cost to total drive capacity).
but, ultimately, I think this is also part of why file-based software
(and OS's which does full reboots, and recompiling software from
source-code, ...) are ultimately preferable to software based solely on
"process images" and "living systems", since in this latter case, if
something crashes or goes terribly wrong, there may be no recovery
(whereas with a file-based system, in the worst case, assuming the HDD
still works, a person can still recover all of their files from the
drive, reinstall the OS and software, and get back to whatever they were
doing).
>> Unfortunately, the C++
>> standard just says that upon Access Violations I will enter the land of UB.
>>
>> I wonder how all those life-critical components for example in the
>> medical or aviation business are written. Probably with some compiler
>> that won't bust upon Access Violations.
>
> Such software must always rely on assumptions not found in the C++
> standard, e.g. what the OS promises. I think the situation would be
> the same if you chose any other mainstream language.
>
>> I mean, what good is a core dump
>> when your plane is already cruising at an altitude of 10.000 feet?
>
> Ever watch Discovery Channel? Lots of people are very interested in
> finding out why a plane crashed. I'm sure there are very detailed
> requirements for this.
>
I once saw an episode of Nova talking about a plane that crashed.
basically, something went wrong (wind speed sensor froze, started
returning 0 wind-speed, causing control software to crash), the plane
sent a crash dump back to the manufacturer over radio, and then the
plane promptly crashed into the ocean.
the manufacturer later found the crash dump and this helped them
identify why the plane crashed.