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:
2025-09-14 11:07:05 -04:00
parent 83af74f4be
commit da0ef64f62
6 changed files with 152 additions and 107 deletions
+24 -13
View File
@@ -10,20 +10,25 @@ namespace smo {
Mind::Mind(void)
: componentThreads{
std::make_shared<ComponentThread>(ComponentThread::DIRECTOR, *this),
std::make_shared<ComponentThread>(ComponentThread::SIMULATOR, *this),
std::make_shared<ComponentThread>(ComponentThread::SUBCONSCIOUS, *this),
std::make_shared<ComponentThread>(ComponentThread::BODY, *this),
std::make_shared<ComponentThread>(ComponentThread::WORLD, *this)
std::make_shared<MindThread>(ComponentThread::DIRECTOR, *this),
std::make_shared<MindThread>(ComponentThread::SIMULATOR, *this),
std::make_shared<MindThread>(ComponentThread::SUBCONSCIOUS, *this),
std::make_shared<MindThread>(ComponentThread::BODY, *this),
std::make_shared<MindThread>(ComponentThread::WORLD, *this)
}
{
}
std::shared_ptr<ComponentThread>
std::shared_ptr<MindThread>
Mind::getComponentThread(ComponentThread::ThreadId id) const
{
// Access the global marionette thread using ComponentThread::getMrntt()
if (id == ComponentThread::MRNTT) { return ComponentThread::getMrntt(); }
if (id == ComponentThread::MRNTT)
{
throw std::runtime_error(
std::string(__func__) +
": MRNTT is not a MindThread and cannot be returned by "
"getComponentThread");
}
// Search through the vector for the thread with matching id
for (auto& thread : componentThreads) {
@@ -32,14 +37,20 @@ Mind::getComponentThread(ComponentThread::ThreadId id) const
// Throw exception if no thread found
throw std::runtime_error(std::string(__func__) +
": No ComponentThread found with ID "
": No MindThread found with ID "
+ std::to_string(static_cast<int>(id)));
}
std::shared_ptr<ComponentThread>
std::shared_ptr<MindThread>
Mind::getComponentThread(const std::string& name) const
{
if (name == "mrntt") { return ComponentThread::getMrntt(); }
if (name == "mrntt")
{
throw std::runtime_error(
std::string(__func__) +
": MRNTT is not a MindThread and cannot be returned by "
"getComponentThread");
}
for (auto& thread : componentThreads) {
if (thread->name == name) { return thread; }
@@ -47,10 +58,10 @@ Mind::getComponentThread(const std::string& name) const
// Throw exception if no thread found
throw std::runtime_error(std::string(__func__) +
": No ComponentThread found with name '" + name + "'");
": No MindThread found with name '" + name + "'");
}
std::vector<std::shared_ptr<ComponentThread>>
std::vector<std::shared_ptr<MindThread>>
Mind::getMindThreads() const
{
return componentThreads;