if (delta_X does not change for one minute) {powerdown();}
Assuming delta_X is the volatile variable, and that its
value changes "all by itself" with no other notifications or
side-effects, I think the best you can do is read delta_X
frequently, and note the time whenever its new value is unequal
to the last-read value:
void call_me_often(void) {
static float old_delta_X = SOME_IMPOSSIBLE_VALUE;
static time_t last_change_time;
float new_delta_X;
time_t current_time;
new_delta_x = delta_X;
current_time = time(NULL);
if (new_delta_x == old_delta_x) {
if (difftime(current_time, last_change_time) >= 60.0)
powerdown();
}
else {
old_delta_X = new_delta_X;
last_change_time = current_time;
}
}
(I'm not sure `float' is correct; adjust as needed. Also, a
free-standing implementation might not have time_t, time(), and
difftime(); substitute whatever timekeeping facilities are
available.)
A drawback of this approach is that if delta_X changes from
42 to 24 and then back to 42 between two call_me_often() calls,
you'll think there was no change. Unless there's more going on
than you've told us, I see no way to avoid the problem. Even
if your environment supports multiple threads of execution and
you can devote a thread to doing nothing but call_me_often()
over and over again, the change-and-change-back vulnerability
will still be there. If you have some knowledge of how fast
delta_X can change, and can poll faster, the problem goes
away -- but if delta_X can change faster than you can poll,
I think you'll just have to hope for the best.
--
Eric Sosman
eso...@ieee-dot-org.invalid
Thanks Eric,
I like your approach and I have used it before. However, I was asking
if the was a simple command in C that does this automatically.
Please don't quote signatures.
> Thanks Eric,
> I like your approach and I have used it before. However, I was asking
> if the was a simple command in C that does this automatically.
There is not.
--
Eric Sosman
eso...@ieee-dot-org.invalid
It also depends on whether or not "delta_X contains 42, and the external
source wrote 42 to delta_X again" counts as "change".
[...]
> I like your approach and I have used it before. However, I was asking
> if the was a simple command in C that does this automatically.
Perhaps the hardware you're on supports hardware breakpoints on memory
accesses? If so, there may be some platform-specific way of saying "has
address X been written to" or "call this function when address X is written to".
But, lacking that, there is nothing available in standard C to
"automatically" do what you are asking.
--
Kenneth Brody