boostorg / statechart

Boost.org statechart module
http://boost.org/libs/statechart
22 stars 43 forks source link

Buffering of events - to make it threadsafe #15

Open Laro88 opened 4 years ago

Laro88 commented 4 years ago

I am trying to familiarize myself sc, however I keep ending up with issues.

I have multiple threads that generate events and I am trying to buffer the events in a std::queue and have a thread call process_event with whatever is in the queue.

//typedef
typedef boost::statechart::state_machine<SMVesselServer, SVesselServer>::event_base_type VSEvent; 
--
//queue def
std::queue<std::shared_ptr<VSEvent>> events;
--
//enqueue function
void HandleEvent(std::shared_ptr<VSEvent> e);

Does this approach make sense at all - any references to thread safety would be great.

Besides, getting interactions with the outside world from the states seems non trivial. I have a static struct with thread safe getters and setters at the moment.