From c880f5b73eb944aeb0ed6692e2deaf44acc8e247 Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Sun, 7 Sep 2025 18:42:28 -0400 Subject: [PATCH] Threading: call initializeSalmanoff after io_service.reset() This enables us to do asynchronous bridging in the functions called by initializeSalmanoff --- smocore/componentThread.cpp | 10 ++++++++++ smocore/marionette/marionette.cpp | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) 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) {