Re: Time outs and state machines



In article <lMSdnfcZUc477Z7ZRVn-pA@xxxxxxxxxxx>,
"Leslie Sanford" <jabberdabber@xxxxxxxxxxxxxxxxx> wrote:

I have a state machine that sends messages to an external device. After
sending each message, the state machine waits for 20 milliseconds. If it
has not received an acknowledgment (ACK) from the receiving device when
the 20 milliseconds have elapsed, it assumes a non-handshaking mode and
sends the next message. On the other hand, if it does receive an
acknowledgment before the 20 milliseconds have elapsed, it sends the
next message immediately.

The way I have implemented this is to have a timer that sends a one-shot
timer event when the specified interval has elapsed, in this case 20
milliseconds. If the state machine receives an acknowledgement from the
receiving device before the timer event has elapsed, it stops the timer,
sends the message, and starts the timer again to begin the whole process
all over again, i.e. send message wait for ACK, etc...

There is a scenario that's probably rare but it's bothering me. Suppose
the receiving device sends an ACK message just before the timer elapsed
event. The ACK message gets put on the queue and immediately after the
timer event places its message on the queue as well. The state machine
consumes the ACK message. The next message in the queue is the timer
event. When the state machine consumes it, it believes that the 20
milliseconds for the last message have elapsed when in fact they have
not.

Hell, the ACK you receive might be from 3 messages back...

I'm not sure what I'm missing, but I'd like my code to me more robust
than this. Is there an additional state that would prevent the above
scenerio? I was thinking about giving each timer event a unique ID as
one approach. When the state machine consumes a timer event, the ID must
be valid for the next message or it is ignored.

That's about the only way. Each ACK must be unique in some way so you
can identify which message it is acknowledging.


--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
.



Relevant Pages

  • Time outs and state machines
    ... I have a state machine that sends messages to an external device. ... the state machine waits for 20 milliseconds. ... receiving device before the timer event has elapsed, it stops the timer, ... The ACK message gets put on the queue and immediately after the ...
    (comp.object)
  • Re: Time outs and state machines
    ... The ACK message gets put on the queue and immediately after the timer event places its message on the queue as well. ... When the state machine consumes it, it believes that the 20 milliseconds for the last message have elapsed when in fact they have not. ... Waiting Patiently | Processed ACK | Processed Timeout ...
    (comp.object)
  • Re: Time outs and state machines
    ... the state machine waits for 20 milliseconds. ... If it has not received an acknowledgment from the receiving device when the 20 milliseconds have elapsed, it assumes a non-handshaking mode and sends the next message. ... timer event when the specified interval has elapsed, ...
    (comp.object)
  • Re: Time outs and state machines
    ... the state machine waits for 20 ... If it has not received an acknowledgment from the ... whether or not the receiving device implements handshaking. ... one-shot timer event when the specified interval has elapsed, ...
    (comp.object)