我很好奇当所有线程内核对象句柄关闭时,线程是否仍然在Win32中运行?当所有线程内核对象句柄关闭时,线程仍在运行
所以我写了一个简单的测试代码像
#include <cstdio>
#include <Windows.h>
#include <process.h>
unsigned int __stdcall thread1_main(void* p)
{
while(1)
printf("thread1 is running!\n");
return 0;
}
int main()
{
HANDLE h = (HANDLE)_beginthreadex(NULL, 0, thread1_main, NULL, 0, NULL);
CloseHandle(h);
while(1)
printf("main thread is running!\n");
return 0;
}
和输出
它看起来像当所有关闭句柄,线程仍在运行。但是,msdn说“只要至少存在一个对象句柄,对象就会保留在内存中”。这很奇怪。