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.