_endthreadex()
-
I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.
-
I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.
Programmer Anju wrote:
The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended?
program listen thread something line this g_bEndListenThread=FALSE; while(1) { if(g_bEndApplication==TRUE) // End listen thread return 0; or _endthreadex(); if(g_bEndListenThread==TRUE) // End listen thread return 0; or _endthreadex(); // Do normal functioning }
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.
Programmer Anju wrote:
The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended?
program listen thread something line this g_bEndListenThread=FALSE; while(1) { if(g_bEndApplication==TRUE) // End listen thread return 0; or _endthreadex(); if(g_bEndListenThread==TRUE) // End listen thread return 0; or _endthreadex(); // Dyour Thread functioning }
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.
If a thread or process terminates, the OS-internal thread/process object is set to signaled state - the state you can use to wait for with e.g. WaitForSingleObject(). So if hThread is your thread handle, the following would wait until the thread has actually terminated: WaitForSingleObject( hThread, INFINITE ) The point is that you might also use the waiting functions to test if an object (in this case the thread) is in signaled state (in this case has terminated) by just using 0 as the timeout value: if( WaitForSingleObject( hThread, 0 ) == WAIT_TIMEOUT ) { // not terminated yet } -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )
-
If a thread or process terminates, the OS-internal thread/process object is set to signaled state - the state you can use to wait for with e.g. WaitForSingleObject(). So if hThread is your thread handle, the following would wait until the thread has actually terminated: WaitForSingleObject( hThread, INFINITE ) The point is that you might also use the waiting functions to test if an object (in this case the thread) is in signaled state (in this case has terminated) by just using 0 as the timeout value: if( WaitForSingleObject( hThread, 0 ) == WAIT_TIMEOUT ) { // not terminated yet } -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )
Daniel Lohmann wrote:
WaitForSingleObject(). So if hThread is your thread handle, the following would wait until the thread has actually terminated: WaitForSingleObject( hThread, INFINITE ) The point is that you might also use the waiting functions to test if an object (in this case the thread) is in signaled state (in this case has terminated) by just using 0 as the timeout value:
In call of TerminateProcess api, system will close the thread, without releasing any of it memory and related stuff. there might be case the system hang indefinatly at the call of WaitForSingleObject api!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You