Click here to Skip to main content
15,920,956 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Whot is wrong with this code? Pin
Glich25-Mar-06 5:50
Glich25-Mar-06 5:50 
GeneralRe: Whot is wrong with this code? Pin
Nemanja Trifunovic25-Mar-06 6:20
Nemanja Trifunovic25-Mar-06 6:20 
GeneralRe: Whot is wrong with this code? Pin
Glich25-Mar-06 6:55
Glich25-Mar-06 6:55 
GeneralRe: Whot is wrong with this code? Pin
PJ Arends25-Mar-06 9:43
professionalPJ Arends25-Mar-06 9:43 
Questiondafs Pin
pravin parmar25-Mar-06 1:38
pravin parmar25-Mar-06 1:38 
Questionhow to check thread is running or not Pin
baldha rakesh25-Mar-06 0:18
baldha rakesh25-Mar-06 0:18 
AnswerRe: how to check thread is running or not Pin
Justin Tay25-Mar-06 0:35
Justin Tay25-Mar-06 0:35 
AnswerRe: how to check thread is running or not Pin
Stephen Hewitt25-Mar-06 1:10
Stephen Hewitt25-Mar-06 1:10 
To tell if a thread is running or not:
DWORD dwState = WaitForSingleObject(hThread, 0);
switch(dwState)
{
case WAIT_TIMEOUT:
     // Thread running.
     break;
case WAIT_OBJECT_0:
     // Thread has exited.
     break;
}


The solution using the GetExitCodeThread API has a flaw. From MSDN:
 "Warning: If a thread happens to return STILL_ACTIVE (259) as an error code, applications that test for this value could end up in an infinite loop."

In general there is no safe way to forcefully terminate a thread (although this doesn't seem to stop people from doing it) - Doing so, by calling TerminateThread for example, can put the process into an unstable state. One way this happens is as follows:
1. The thread about to be terminated calls an API which enters a critical section by calling EnterCriticalSection.
2. It is terminated before it can call LeaveCriticalSection.
3. Another thread calls the same API and it deadlocks: This API is now broken and any thread calling it will now deadlock.
This really happens and I can tell you from experience that tracking down the problem is not pleasant.

The general solution to this problem is to program the thread so you can arrange for it to exit, typically by signaling an event and then waiting for it to terminate.


Steve
GeneralRe: how to check thread is running or not Pin
Justin Tay25-Mar-06 1:42
Justin Tay25-Mar-06 1:42 
GeneralRe: how to check thread is running or not Pin
ThatsAlok25-Mar-06 6:04
ThatsAlok25-Mar-06 6:04 
GeneralRe: how to check thread is running or not Pin
Stephen Hewitt26-Mar-06 12:20
Stephen Hewitt26-Mar-06 12:20 
GeneralRe: how to check thread is running or not Pin
ThatsAlok26-Mar-06 17:55
ThatsAlok26-Mar-06 17:55 
QuestionDraw barcode and MapMode Pin
includeh1024-Mar-06 23:55
includeh1024-Mar-06 23:55 
QuestionSending Fax using the FaxSendDocuemnt API Pin
aasstt24-Mar-06 23:02
aasstt24-Mar-06 23:02 
QuestionProblem with Controls on dialog box with images Pin
Ganesh_T24-Mar-06 21:50
Ganesh_T24-Mar-06 21:50 
AnswerRe: Problem with Controls on dialog box with images Pin
Hamid_RT29-Mar-06 6:46
Hamid_RT29-Mar-06 6:46 
GeneralRe: Problem with Controls on dialog box with images Pin
Ganesh_T29-Mar-06 19:20
Ganesh_T29-Mar-06 19:20 
GeneralRe: Problem with Controls on dialog box with images Pin
Hamid_RT30-Mar-06 2:01
Hamid_RT30-Mar-06 2:01 
Questionpure C question about accessing bits Pin
bouli24-Mar-06 21:42
bouli24-Mar-06 21:42 
AnswerRe: pure C question about accessing bits Pin
Justin Tay25-Mar-06 0:17
Justin Tay25-Mar-06 0:17 
GeneralRe: pure C question about accessing bits Pin
bouli25-Mar-06 2:48
bouli25-Mar-06 2:48 
GeneralRe: pure C question about accessing bits Pin
Justin Tay25-Mar-06 5:25
Justin Tay25-Mar-06 5:25 
GeneralRe: pure C question about accessing bits Pin
bouli25-Mar-06 6:16
bouli25-Mar-06 6:16 
GeneralRe: pure C question about accessing bits Pin
Justin Tay25-Mar-06 6:33
Justin Tay25-Mar-06 6:33 
GeneralRe: pure C question about accessing bits Pin
bouli25-Mar-06 6:50
bouli25-Mar-06 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.