Can't happen you say? I have a situation where it DOES happen. Consider this:
When foo2 tries to access the memory, an access violation occours. Uncomment foo3 and comment out foo2 and there will be no access violation. The only difference is that foo2 takes a reference and foo3 takes by value.Code:struct foo_s { ppnew<int> pint; }; void foo2(pp<int>& pTest) { Sleep(10000); int n = *pTest; n; } void foo3(pp<int> pTest) { Sleep(10000); int n = *pTest; n; } DWORD WINAPI foo(void* pParameter) { foo_s* p = (foo_s*)pParameter; foo2(p->pint); //foo3(p->pint); // Works if you call this function instead. return 0; } BOOL CKantanAnimeApp::InitInstance() { foo_s* ps = new foo_s; *ps->pint = 100; //NewThread(&CKantanAnimeApp::foo, this, ps->pint); ::CreateThread(NULL, NULL, &foo, ps, NULL, NULL); Sleep(1000); int n = *ps->pint; n; delete ps; Sleep(100000); ... }



LinkBack URL
About LinkBacks




