Skip to main content
GameDev.net gamedev.net
🔒 Locked

CreateThread Question

Started by b1gjo3 Jul 8, 2009 at 11:55 AM 4 replies 1.3k views
Original Post
b1gjo3
b1gjo3
If my thread function runs on an infinite loop, if i use CloseHandle on that thread, will it terminate the loop? thanks
the_edd
the_edd
Quote:
Original post by b1gjo3
If my thread function runs on an infinite loop, if i use CloseHandle on that thread, will it terminate the loop? thanks


I don't know the answer, but in general you really don't want to kill a thread like that. It would have no chance to clean up after itself.

Instead, set a shared flag that the looping thread looks at periodically.
david_watt78
david_watt78
I assume not. It would only get rid of the handle to the thread not the thread you will need to call KillThread first or return from the thread function to stop the thread.
Brother Bob
Brother Bob
Why ask, or assume, when the answer is just 10 seconds away using a search engine? Clicky. Took me longer to type that than to find the actual answer.
Anon Mike
Anon Mike
No, closing a handle to a thread will not terminate the thread. And terminating threads like that is a really realy really bad idea anyway. You should instead signal the thread to cleanly exit on it's own.
-Mike

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.