Following doesn't work, because even though the variable is volatile, it actually writes the value to a different address than the MyLocalVar, as its value doesn't change.
Code:
bool bExit = false;
void Thread1(const int& rMyLocalVar)
{
while (!bExit)
{
cout << rMyLocalVar << endl;
Sleep(100);
}
}
void Help()
{
volatile UINT MyLocalVar = 0;
CWinThread* pThread;
Stuff::NewThreadTF(&pThread, MyLocalVar, &Thread1);
for (int i = 0; i < 0xFFFFFFFF; i++)
{
MyLocalVar++;
//if (i % 1000) cout << MyLocalVar << endl;
}
bExit = true;
WaitForSingleObject(pThread->m_hThread, INFINITE);
}