class A
{
public:
int a,b;
void execute();
};class B
{
public:
CWinThread* m_pThread;
A *ObjA;
static UINT ThreadFunction(LPVOID pParam);
B();
~B();
};
void A::execute()
{
for(int i=0;i<10000;i++)
{
a=b+1;
}
};
UINT B::ThreadFunction(LPVOID pParam)
{
B *pJQ = (B *)pParam;
while(1)
{
pJQ->ObjA->execute();
}
}
B::B()
{
ObjA=new A;
m_pThread = AfxBeginThread(ThreadFunction,this);
}
B::~B()
{
m_pThread->ExitInstance();
delete m_pThread;
delete ObjA;
}
我在析构B时,ExitInstance()并没有从ObjA的execute退出,造成读写错误,请问如何更正?
{
public:
int a,b;
void execute();
};class B
{
public:
CWinThread* m_pThread;
A *ObjA;
static UINT ThreadFunction(LPVOID pParam);
B();
~B();
};
void A::execute()
{
for(int i=0;i<10000;i++)
{
a=b+1;
}
};
UINT B::ThreadFunction(LPVOID pParam)
{
B *pJQ = (B *)pParam;
while(1)
{
pJQ->ObjA->execute();
}
}
B::B()
{
ObjA=new A;
m_pThread = AfxBeginThread(ThreadFunction,this);
}
B::~B()
{
m_pThread->ExitInstance();
delete m_pThread;
delete ObjA;
}
我在析构B时,ExitInstance()并没有从ObjA的execute退出,造成读写错误,请问如何更正?
这是我的理解,但愿对你有所帮助。