multithreading - when all thread kernel object handles is closed, does the thread still running -
i'm curious when thread kernel object handles closed, thread still running in win32?
so write simple test codes like
#include <cstdio> #include <windows.h> #include <process.h> unsigned int __stdcall thread1_main(void* p) { while(1) printf("thread1 running!\n"); return 0; } int main() { handle h = (handle)_beginthreadex(null, 0, thread1_main, null, 0, null); closehandle(h); while(1) printf("main thread running!\n"); return 0; }
and output
it looks when handle closed, thread still running. however, msdn says "an object remains in memory long @ least 1 object handle exists". strange.
yes, thread run until exits (by returning initial thread procedure), forcibly terminated (via terminatethread
or _endthread(ex)
), or parent process exits. whether handles thread exist or not irrelevant.
if think it, never work other way - since can wait on thread handle determine if has exited or not, definition thread lifetime unrelated lifetime of handle.
Comments
Post a Comment