Split CompThread=>MindThr+MrnttThr; alloc globalMind in mrnttMain
We now allocate globalMind locally inside of marionetteMain. Why? Before now, we had an asymmetric threading situation where the globalMind's threads were initialized at during global constructor invocation and not on demand. This meant that we had to shut down those threads even if we had never got to the point of calling Mind::initializeReq. This significantly complicated our shutdown sequence since we had to factor in the lifetime of the std::thread objects inside of the ComponentThreads which were inside of the globalMind object. Now, if we hadn't called Mind::initializeReq, we don't have to perform any Mind::finalizeReq or adjacent operations. Shutdown is symmetrically mirrored against the operations we actually performed during execution. We introduced some complexity by splitting ComponentThreads into two derivative types (MindThread and MarionetteThread) but I think in the long term we'll be able to massage this split into a much cleaner situation overall.
This commit is contained in:
@@ -13,13 +13,6 @@
|
||||
|
||||
namespace smo {
|
||||
|
||||
// Global Mind instance
|
||||
std::shared_ptr<Mind> globalMind = std::make_shared<Mind>();
|
||||
|
||||
// Global marionette thread instance
|
||||
std::shared_ptr<ComponentThread> mrntt::mrntt =
|
||||
std::make_shared<ComponentThread>(ComponentThread::MRNTT, *globalMind);
|
||||
|
||||
CrtCommandLineArgs crtCommandLineArgs(0, nullptr, nullptr);
|
||||
|
||||
void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[])
|
||||
@@ -27,8 +20,13 @@ void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[])
|
||||
crtCommandLineArgs = CrtCommandLineArgs(argc, argv, envp);
|
||||
}
|
||||
|
||||
// Global Mind instance
|
||||
std::shared_ptr<Mind> globalMind;
|
||||
|
||||
namespace mrntt {
|
||||
std::atomic<int> exitCode;
|
||||
// Global marionette thread instance
|
||||
std::shared_ptr<MarionetteThread> mrntt = std::make_shared<MarionetteThread>();
|
||||
|
||||
void exitMarionetteLoop()
|
||||
{
|
||||
@@ -39,7 +37,7 @@ void exitMarionetteLoop()
|
||||
|
||||
} // namespace mrntt
|
||||
|
||||
void ComponentThread::marionetteMain(ComponentThread& self)
|
||||
void MarionetteThread::main(MarionetteThread& self)
|
||||
{
|
||||
// Wait for CRT's main() to post us the command line args.
|
||||
std::cout << __func__ << ": Waiting for command line JOLT" << std::endl;
|
||||
@@ -111,6 +109,8 @@ void ComponentThread::marionetteMain(ComponentThread& self)
|
||||
* The latter is cleaner and more resource-respecting. The former is
|
||||
* easier to implement.
|
||||
*/
|
||||
// Create new Mind instance just before initializeReq
|
||||
globalMind = std::make_shared<Mind>();
|
||||
globalMind->initializeReq(
|
||||
[](bool success)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user