大概是这个样子的 int main() { void* p=NULL; thread1=createThread(NULL,0 ,threadTest,p,0,&ThradID) waitfor... 等待线程结束 int m=*((int*)p); //不能访问} threadtest(void*p) { int a=1; p=&a; }
threadtest(void*p) { int a=1; p=&a; } ===== 你这里的a是局部变量,在主线程中调用int m=*((int*)p);时线程函数结束后a就收回了,当然访问不了。
int main() { int* p = new int; thread1=createThread(NULL,0 ,threadTest,(void*)p,0,&ThradID) waitfor... 等待线程结束 int m=*((int*)p); //不能访问} threadtest(void*p) { int a=1; *(int*)p = a; }
BOOL GetExitCodeThread(
HANDLE hThread,
LPDWORD lpExitCode
);
得到。
int main()
{
void* p=NULL;
thread1=createThread(NULL,0 ,threadTest,p,0,&ThradID)
waitfor... 等待线程结束
int m=*((int*)p); //不能访问}
threadtest(void*p)
{
int a=1;
p=&a;
}
{
int a=1;
p=&a;
}
=====
你这里的a是局部变量,在主线程中调用int m=*((int*)p);时线程函数结束后a就收回了,当然访问不了。
{
int* p = new int;
thread1=createThread(NULL,0 ,threadTest,(void*)p,0,&ThradID)
waitfor... 等待线程结束
int m=*((int*)p); //不能访问}
threadtest(void*p)
{
int a=1;
*(int*)p = a;
}