Using nested active schedulers

If one is facing a situation where a non-active object using system needs to interact with an active object system in the same process and thread it might be useful to consider the use of nested active schedulers. It’s ugly in a way, but if done correctly it can be a good solution.

If there is one method that is blocking in the non-active object system which should still appear to be blocking to that system but it should while “blocking” execute pending active objects. If that’s the case this can be accomplished by wrapping the “blocking” method in an active object and starting a nested active scheduler (with CActiveScheduler::Start()) in the beginning of the “blocking” method but after the async request has been initiated. The RunL() method for this active object only stops the nested scheduler (with CActiveScheduler::Stop()) which resumes execution after the CActiveScheduler::Start() done in the “blocking” method.

Note however that one needs to have one active scheduler running before doing the above for this to work. But if that’s not the case, that can be fixed by using another active object…