Sign in to follow this  

Problem at the end of thread?

This topic is 4521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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):


//...
typedef queue<CString &> DATAQUEUE;
//...


That's better code, and probably faster. ;)

Share this post


Link to post
Share on other sites
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. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this