NoHero
December 29th, 2004, 08:11 AM
Hi Folks,
I have a very dumm question. I help somebody with his project and he has the problem that he creates threads but never closes its handle. So after several hours of running he will run out of resources for his threads. Since I read
The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle.
this in MSDN I try to figure out ways how to close all the thread handles. It creates threads depending on the operation to be done. Let's say the client needs some calculation to be done, only if the calculation is bigger than X it will create a thread to handle it. But how do I close the threads handle, returned by CreateThread()? Shall I give it the thread procedure and he should close it before the thread returns? Shall I introduce some kind of thread garbage collection that has every handle in an array and waits for them to exit to close their handle? It's just a design question, so please help me folks.
I think I should add something: It is not my project though. Our school administrator wrote that in the holi days to handle the students "misfortunes" ;) and I think he has never heard about thread pooling. But in that case it doesn't matter anyway because the project is far too big to make a general redesign. So I need to solve the problem the way described above. If I would have written this it would include a thread pool but ....
Thanks in Advance, Best Regards
Florian
I have a very dumm question. I help somebody with his project and he has the problem that he creates threads but never closes its handle. So after several hours of running he will run out of resources for his threads. Since I read
The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle.
this in MSDN I try to figure out ways how to close all the thread handles. It creates threads depending on the operation to be done. Let's say the client needs some calculation to be done, only if the calculation is bigger than X it will create a thread to handle it. But how do I close the threads handle, returned by CreateThread()? Shall I give it the thread procedure and he should close it before the thread returns? Shall I introduce some kind of thread garbage collection that has every handle in an array and waits for them to exit to close their handle? It's just a design question, so please help me folks.
I think I should add something: It is not my project though. Our school administrator wrote that in the holi days to handle the students "misfortunes" ;) and I think he has never heard about thread pooling. But in that case it doesn't matter anyway because the project is far too big to make a general redesign. So I need to solve the problem the way described above. If I would have written this it would include a thread pool but ....
Thanks in Advance, Best Regards
Florian