vendredi 17 avril 2020

Use "Class Member Access Operator overloading" to provide interruption points

I have a few c++ classes with thousands of lines of code in each. There is a high-level state machine which is the source of all other functions calls (root of the call stack).

I want to be able to cancel the execution at any time. For example, it is in the middle of one state, I won't stop the code right away and jump to another state.

This is my plan and I want to know if it makes sense or if you guys see a big downside in this approach:

1- In each state, create a boost thread and run the code inside that thread 2- If "cancel" is requested call thread.interrupt() function 3- Overload "->" operator of the classes and put "boost::this_thread::interruption_point();" before and after all the function calls

With this approach I expect each state to be interrupted before the next member function call or after the current member function call

Does this work? Do you have a better approach? All helps are really appreciated

** It would be much better if I had very quick states (short execution time). Then I could change the state right in the state machine without the need to interrupt a state. However, the code I am working with is far from that design, unfortunately.

Aucun commentaire:

Enregistrer un commentaire