I have long-running function in my C++ 11 application that is essentially sub_main. I need to inform this function about situation risen in different thread. Requirements:
- The
situationcan be risen at any time - The application should handle the
situationat most at single place (it can leave it unhandled as well) - It does not need to be ultra fast nor not-delayed in execution
As of now I considered two option:
- Pass object factory with factoree that contain internal queue of
situations. The object is then polled at regular interval insidesub_mainfor newsituations. Polled object is removed from queue. When application decide it will not handle the situation in particular place, it can move it back to globalsituationsqueue and next constructed factoree will get thesituation(so it can be handled elsewhere insub_main) - Analogous situation, but instead of polling, use lambda function that updates local variable inside
sub_mainas needed. This version does not use continous polling, but is less readable
Both seems a bit complicated and I am wondering if I missed a more simple solution. The problem is the sub_main is being implemented outside of my library and I am providing end-user with my situations