C11 5.1.2.3/5:
When the processing of the abstract machine is interrupted by receipt of a signal, the values of objects that are neither lock-free atomic objects nor of type volatile sig_atomic_t are unspecified, as is the state of the floating-point environment. The value of any object modified by the handler that is neither a lock-free atomic object nor of type volatile sig_atomic_t becomes indeterminate when the handler exits, as does the state of the floating-point environment if it is modified by the handler and not restored to its original state.
This question is specifically about embedded systems, in a situation where there is no operating system-like setup.
On an embedded system classic signals (POSIX style) do not exist. Say we have an interrupt which calls multiple functions, all of whom work on the same ((semi-) global) variable, but this variable is not used from an out-of-interrupt context. Something like
static enum State state;
static void setStateTo1(void)
{
state = stateOne;
}
static void setStateTo2(void)
{
state = stateTwo;
}
void ISR(void)
{
if (state == stateOne)
setStateTo2();
else
setStateTo1();
}
Two questions:
- Is an interrupt a signal?
- Is the above code an example of undefined behaviour, because
stateis notvolatile?