undefined states

Jan 08, 2005 8 Replies

just a quick question,



How do you design your code to prevent it slipping into an undefined state, i thought all that was needed was to create a default to first state in case the program slips outside the defined area.



Any help would be greatly appreciated


We need more context to give a useful answer. In general, stay within the defined areas of your programming language, tools, and target hardware.

Thad

Writing a program to default to a given state when things go wrong is like building a road with guardrails on corners -- it keeps you from getting into deeper trouble, but it doesn't prevent the original screw-up. Careful coding, or using language constructs that don't allow an illegal state to be assigned, are the only things that will keep things from screwing up in the first place.

I suggest you follow up this or Mr. Smith's post with a post that tells what you're trying to do and what's screwing up. It's most likely that you're either explicitly writing the wrong value to your state someplace, or that you've got a pointer wrong and you're writing some perfectly valid piece of data to a horribly wrong spot.

Tim Wescott Wescott Design Services http://www.wescottdesign.com

Undefined states are to be avoided at almost all cost. This would result in a non-deterministic behaviour. Therefore : statemachines have to define all states. Overflows in addition/subtraction and multiplications have to be trapped or avoided. A division by zero has also to be trapped or avoided. In the embedded world, there is command.com that takes charge - usually. The watchdog shall be quiet.

Rene

Defensive programming is a must!!!!!!!!!!

gm

Use a well defined state machine.

The following article might help:

formatting link

Deepa

--

formatting link
EventStudio 2.5 - Embedded System Modeling with Sequence Diagrams

Just what is 'slipping' in this context?

In any case:

In general, you can't design software that can detect it's own malfunction. Search for "halting problem" on the 'net.

The best you can do is a "watchdog timer" or some other hardware to monitor the software operation.

If the problem is due to programmer error then you can minimize it by hiring experienced programmers and system testers.

??????????????

Nicholas O. Lindan, Cleveland, Ohio Consulting Engineer: Electronics; Informatics; Photonics. Remove spaces etc. to reply: n o lindan at net com dot com psst.. want to buy an f-stop timer? nolindan.com/da/fstop/

Never thought about it. A finite state machine is often a machine that's trivial to code for, where some code contains thousands or millions of states, and the correctness of all combinations of states is not an interesting question, or even humanly possible to analyze.

One state might be a system call failure that is not accounted for, and the code crashes or malfunctions. The obvious prevention for such is to check the success and not assume. The pitfall here was a branch, not in the algorithm, but in the machine, that was not recognized as such.

as other people have said, watchdogs are OK

formatting link
and
formatting link

martin

Serious error. All shortcuts have disappeared. Screen. Mind. Both are blank.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required