diff --git a/smocore/componentThread.cpp b/smocore/componentThread.cpp index 7f79552..3fb3b4b 100644 --- a/smocore/componentThread.cpp +++ b/smocore/componentThread.cpp @@ -57,6 +57,16 @@ void ComponentThread::main(ComponentThread& self) bool sendExceptionInd = false; try { + /** EXPLANATION: + * This reset() call is crucial for async bridging patterns + * to work. + * When the outermost thread's io_service is stop()ped (e.g., + * from JOLT sequence), it won't process any new work until + * reset() is called, even if nested async operations try to + * post work to it. This means async bridges invoked from + * the outermost thread main sequence won't work until this + * reset() call. + */ self.getIoService().reset(); self.getIoService().run(); } diff --git a/smocore/marionette/marionette.cpp b/smocore/marionette/marionette.cpp index 9d6904f..54cd1a5 100644 --- a/smocore/marionette/marionette.cpp +++ b/smocore/marionette/marionette.cpp @@ -85,10 +85,11 @@ void ComponentThread::marionetteMain(ComponentThread& self) throw JustPrintUsageNoError(options); } - initializeSalmanoff(mrntt::mrntt); self.getIoService().post([]() { - // Initialize the global Mind object + // Initialize Salmanoff first + initializeSalmanoff(mrntt::mrntt); + // Then initialize the global Mind object globalMind->initialize(); }); @@ -105,8 +106,18 @@ void ComponentThread::marionetteMain(ComponentThread& self) { bool sendExceptionInd = false; try { - self.getIoService().reset(); - self.getIoService().run(); + /** EXPLANATION: + * This reset() call is crucial for async bridging patterns + * to work. + * When the outermost thread's io_service is stop()ped (e.g., + * from JOLT sequence), it won't process any new work until + * reset() is called, even if nested async operations try to + * post work to it. This means async bridges invoked from + * the outermost thread main sequence won't work until this + * reset() call. + */ + self.getIoService().reset(); + self.getIoService().run(); } catch (const std::exception& e) {