Time outs and state machines
- From: "Leslie Sanford" <jabberdabber@xxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Feb 2006 15:33:49 -0600
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.
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.
Any help is appreciated.
.
- Follow-Ups:
- Re: Time outs and state machines
- From: H. S. Lahman
- Re: Time outs and state machines
- From: Dmitry A. Kazakov
- Re: Time outs and state machines
- From: Robert Oliver
- Re: Time outs and state machines
- From: Daniel T.
- Re: Time outs and state machines
- Prev by Date: Re: OOP can be simply summed up as 'passing messages to objects'
- Next by Date: Re: Time outs and state machines
- Previous by thread: Re: OOP can be simply summed up as 'passing messages to objects'
- Next by thread: Re: Time outs and state machines
- Index(es):
Relevant Pages
|