Sign in to follow this  
tranduy

Problem at the end of thread?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this