S
Sacha
Consider I have a working thread like this,
while (1)
{
if ( g_pObject ) g_pObject->DoOneStep();
}
with an class hierarchie like this
class CBase
{
public:
virtual void Special() = 0;
void DoOneStep()
{
Special();
};
};
class A: public CBase
{
void Special();
};
class B: public CBase
{
void Special();
};
And a control thread, which is able to swap objects while the working
thread is running:
//global objects and pointer:
A a;
B b;
CBase *g_pObject;
g_pObject = &a;
// and later on...
g_pObject = &b;
I also use a HANDLE, which is a static member of CBase, to synchronize
object member calls from within the working and control thread.
To have an idea about the timimg:
DoOneStep is called about every 10 ms, an object swap (or object member
call) occurs upon user interactio, so lets say every 10s.
Is this safe, if there is a consistent state after every DoOneStep?
What could I do better?
The whole thing is a quick and dirty project, and the object(s) are
already well elaborated. Historically, there was only one object, and I
did not need to swap. Inheritance seems to be the easiest way to proceed
with different objects/classes.
I prefer a quick and not so dirty solution rather than a complete
redesign...
Thanks for any insight
-Sacha
while (1)
{
if ( g_pObject ) g_pObject->DoOneStep();
}
with an class hierarchie like this
class CBase
{
public:
virtual void Special() = 0;
void DoOneStep()
{
Special();
};
};
class A: public CBase
{
void Special();
};
class B: public CBase
{
void Special();
};
And a control thread, which is able to swap objects while the working
thread is running:
//global objects and pointer:
A a;
B b;
CBase *g_pObject;
g_pObject = &a;
// and later on...
g_pObject = &b;
I also use a HANDLE, which is a static member of CBase, to synchronize
object member calls from within the working and control thread.
To have an idea about the timimg:
DoOneStep is called about every 10 ms, an object swap (or object member
call) occurs upon user interactio, so lets say every 10s.
Is this safe, if there is a consistent state after every DoOneStep?
What could I do better?
The whole thing is a quick and dirty project, and the object(s) are
already well elaborated. Historically, there was only one object, and I
did not need to swap. Inheritance seems to be the easiest way to proceed
with different objects/classes.
I prefer a quick and not so dirty solution rather than a complete
redesign...
Thanks for any insight
-Sacha