I need a static variable that points to itself to use when referencing the object in a thread method. I am trying to use the _beginthread method in process.h Many objects of this type are going to be using the thread method. Currently this is failing because the instance variable is shared across the whole class. I need the instance variable to be static to use in the threadLoop and need it to reference the object. Any suggestions?
Header: static Nodes *instance;
Implementation: Nodes *Nodes::instance = NULL;
main.cpp:
for(int c = 0; c < 7; c++)
{
nodesVect.push_back(Nodes(c, c+10));
}
for(int c = 0; c < 7; c++)
{
nodesVect.at(c).init(); // init() { instance = this; }
}
My _beginthreadex() usage is as follows;
a cStartable base class
the majic is:
and a utility cThread class.
things that need a thread inherit from startable and implement their Run.
I’ve edited my code quite a lot here. It is all very robust and quiet powerful to beable to spawn multiple thread instances all at once off a single object and have it be so clean at the subclass level.
the point of all of this is that cNode::Run() gets passed a per thread instance object into which per thread instance heap data could be attached. otherwise all thread instances share their single class instance as their “memory space”. I like it 🙂
If you need more details I’m happy to share.