I came across this code in a large codebase
DWORD WINAPI ThreadFunc (LPVOID lpParam)
{
int *x = 0;
*x = 1234; // Access violation
return 0;
}
void Manager::Crash ()
{
Log("Received a remote command to crash Server.");
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread = ::CreateThread(NULL, 0, ThreadFunc, &dwThrdParam, 0, &dwThreadId);
}
My question is: Why is it using a thread? Would it be more or less threadsafe if the code in ThreadFunc was done directly in Manager::Crash? I am reluctant to make changes in case I remove the crash.
He doesn’t want to handle the exception that occurs. The original thread that received the
Manager::Crashcontinues. An AV exception does not necessarily terminate the process. Although in this case the fact that is not handled by a__try/__exceptblock (note, is a SEH try block, not the C++ one) then the unhandled second chance exception will terminate the process. But perhaps he want to force Dr. Watson/WER to jump in, or the post-mortem debugger to launch, or to break into current debugger. Who knows…Actually, d’oh! IF the main thread does have a SEH handler installed, it will not crash the process. QED.