Click here to Skip to main content
15,896,063 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CString::FormatMessage STL equivalent ? Pin
Anthony_Yio14-Feb-06 15:47
Anthony_Yio14-Feb-06 15:47 
QuestionDelete Directory and its child files and folders from a specified location Pin
zahid_ash14-Feb-06 4:14
zahid_ash14-Feb-06 4:14 
AnswerRe: Delete Directory and its child files and folders from a specified location Pin
David Crow14-Feb-06 4:20
David Crow14-Feb-06 4:20 
GeneralRe: Delete Directory and its child files and folders from a specified location Pin
zahid_ash14-Feb-06 4:40
zahid_ash14-Feb-06 4:40 
GeneralRe: Delete Directory and its child files and folders from a specified location Pin
David Crow14-Feb-06 4:55
David Crow14-Feb-06 4:55 
GeneralRe: Delete Directory and its child files and folders from a specified location Pin
Michael Dunn14-Feb-06 7:34
sitebuilderMichael Dunn14-Feb-06 7:34 
AnswerRe: Delete Directory and its child files and folders from a specified location Pin
Blake Miller14-Feb-06 4:24
Blake Miller14-Feb-06 4:24 
Questionwavetotext Pin
kiranvcpp14-Feb-06 4:14
kiranvcpp14-Feb-06 4:14 
AnswerRe: wavetotext Pin
toxcct14-Feb-06 4:17
toxcct14-Feb-06 4:17 
GeneralRe: wavetotext Pin
Eytukan14-Feb-06 4:59
Eytukan14-Feb-06 4:59 
QuestionUpdating DB table with CRecordset class Pin
zinc_z14-Feb-06 4:04
zinc_z14-Feb-06 4:04 
QuestionRe: Updating DB table with CRecordset class Pin
David Crow14-Feb-06 4:22
David Crow14-Feb-06 4:22 
AnswerRe: Updating DB table with CRecordset class Pin
zinc_z15-Feb-06 3:21
zinc_z15-Feb-06 3:21 
AnswerRe: Updating DB table with CRecordset class Pin
Wes Aday14-Feb-06 4:23
professionalWes Aday14-Feb-06 4:23 
GeneralRe: Updating DB table with CRecordset class Pin
zinc_z15-Feb-06 3:25
zinc_z15-Feb-06 3:25 
QuestionMFC and edit controls Pin
LCI14-Feb-06 3:51
LCI14-Feb-06 3:51 
AnswerRe: MFC and edit controls Pin
Eytukan14-Feb-06 3:56
Eytukan14-Feb-06 3:56 
GeneralRe: MFC and edit controls Pin
LCI14-Feb-06 4:04
LCI14-Feb-06 4:04 
GeneralRe: MFC and edit controls Pin
toxcct14-Feb-06 4:07
toxcct14-Feb-06 4:07 
AnswerRe: MFC and edit controls Pin
David Crow14-Feb-06 4:24
David Crow14-Feb-06 4:24 
QuestionTerminating a blocked thread Pin
masnu14-Feb-06 3:47
masnu14-Feb-06 3:47 
AnswerRe: Terminating a blocked thread Pin
Calc2014-Feb-06 4:16
Calc2014-Feb-06 4:16 
GeneralRe: Terminating a blocked thread Pin
Stephen Hewitt14-Feb-06 11:57
Stephen Hewitt14-Feb-06 11:57 
Your asking for trouble even thinking of calling TerminateThread. Here's an example program which shows the kind of thing that can go wrong:

------------------------------------------
#include <windows.h>

CRITICAL_SECTION g_cs;

void ShowMessageBox()
{
EnterCriticalSection(&g_cs);
MessageBox(NULL, "Hello", "ShowMessageBox", MB_OK);
LeaveCriticalSection(&g_cs);
}

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
ShowMessageBox();
return 0;
}

int main(int argc, char* argv[])
{
InitializeCriticalSection(&g_cs);

// Start thread.
DWORD ThreadID;
HANDLE hThread = CreateThread(NULL, 0, &ThreadProc, 0, 0, &ThreadID);

// Wait for one second then kill the thread.
// It still holds the CRITICAL_SECTION!!!
Sleep(1000);
TerminateThread(hThread, 0);

// We've killed the "ShowMessageBox" API, permanently, calling it now
// causes this thread to dead lock!
ShowMessageBox();

DeleteCriticalSection(&g_cs);

return 0;
}
------------------------------------------

In this program calling TerminateThread permanently breaks ShowMessageBox because we killed the thread when it still held a lock. This is the worst kind of bug as it's very hard to reproduce as it's sensitive to timing. If you're calling Win32 functions many of them will briefly hold locks, if you terminate a thread while it is hold such a lock you're screwed.

Moral: Don't call TerminateThread. There are exceptions but very few.

Steve
AnswerRe: Terminating a blocked thread Pin
David Crow14-Feb-06 4:29
David Crow14-Feb-06 4:29 
GeneralRe: Terminating a blocked thread Pin
masnu14-Feb-06 4:31
masnu14-Feb-06 4:31 

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.