Threading
-
I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread.
pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread();
thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know where -
I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread.
pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread();
thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know wherewell the Error I am getting is Debug Assertion Failed. File: WinCore.cpp Line: 1002 well is this problem of my thread. :s
-
I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread.
pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread();
thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know whereHallo, I had a simmilar problem and I solved the problem by using a shared bool var. if the var is set to true from outside the thread terminats its self. Try to use it. Meinhard
-
Hallo, I had a simmilar problem and I solved the problem by using a shared bool var. if the var is set to true from outside the thread terminats its self. Try to use it. Meinhard
thanks for your reply well my problem solved the problem was i was trying to access a class function when there was no class object .. i mean with empty pointer :D .. and there was one more problem that if i start the thread again before it ends up or the class object is destroyed this create problem because thread is still using the class and class object was deleted .. so i make 2 boolean when destructor call comes one goes to false and destructor goes in an empty loop and this false boolean tell thread ok end now. before thread ends it false the other one too .. to tell destructor ok i m finish now .. so destructor comes out of loop and object destroy. it is something like syncronization .. or what ever :) but problem is solved
-
I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread.
pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread();
thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know whereSee http://flounder.com/workerthreads.htm for how to properly shutdown a thread.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown