Problem at the end of thread?
Hello all,
I have a class like this:
class CServerDlg{
//...
using namespace std;
typedef queue<CString> DATAQUEUE;
DATAQUEUE dataQueue;
//...
public:
bool CheckValid();
static void myThrProc(LPVOID pParam);
void CheckData(CString strData);
//...
};
bool CServerDlg::CheckValid()
{
//...
if (!dataQueue.empty())
{
AfxBeginThread((AFX_THREADPROC)myThrProc, (LPVOID)this);
}
//...
}
void CServerDlg::myThrProc(LPVOID pParam)
{
//---------------------------------------------- my problem
CString strData = dataQueue.front();
dataQueue.pop();
//---------------------------------------------- is here
//... do something with strData. It done.
CServerDlg *mServ = (CServerDlg*) pParam;
mServ->CheckData(strData);
return;
}
My problem is after the thread has finished, I had an error message (debug assertion) but I really don't know why I'm wrong. If can, pls explains for me.
Thank you very much,
Regards.
Well, this may or may not be the problem, but instead of queueing the WHOLE CString, it's better to just queue a pointer or reference (in this case, reference is probably better so you don't have to modify much code):
That's better code, and probably faster. ;)
//...typedef queue<CString &> DATAQUEUE;//...
That's better code, and probably faster. ;)
Something else I just noticed. Your thread function is static (meaning it has no access to nonstatic members of CServerDlg), but DATAQUEUE dataQueue isn't static. That could be a cause of error, though that should be a compile time error, not a runtime error. So there's something missing there. ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement