Boost logo

Boost Users :

Subject: [Boost-users] [Statechart] Implementing an internal timeout in an asynchronous state machine
From: John Buonassisi (johnbuonassisi_at_[hidden])
Date: 2016-01-07 14:47:33


Hi there,

I am looking for some advice on the best way to implement an internal
timeout in an asynchronous state machine using the Boost Statechart
library. My project requires an asynchronous state machine that multiple
threads can queue events to. The asynchronous state machine will react to
events and execute callback functions that are registered on creation of
the state machine. So far, this hasn't been a problem, but I have hit a bit
of a roadblock when handling timeouts. I need my asynchronous state machine
class to start a timer in a certain reaction method, when this timer
expires I need the scheduler to queue a timeout event. Basically, the timer
will act as an interrupt, when it expires I need a timeout event to be
immediately queued to the state machine event queue.

Since asynchronous state machines are created and managed by a scheduler
class (in my case boost::statechart::fifo_scheduler<>) how can I get the
asynchronous state machine to queue a timeout event? If possible, I would
like to encapsulate this timeout functionality, so client code that uses my
derived asynchronous state machine does not have to deal with managing
timeouts.

My first thought is to have the asynchronous state machine class create a
thread when the timer is started. The thread will continually check if the
timer has expired and if it has, will queue a timeout event. The issue with
this approach is that I would need to pass the scheduler and state machine
handler to the thread function in order to queue the event. Obviously, the
state machine does not have access to these objects and I am unsure if this
is a safe approach.

Any suggestions or help with this matter would be greatly appreciated! This
is my first post to the mailing list so I hope this is the right arena for
my question.

Thanks,
John Buonassisi



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net