Boost logo

Boost Users :

Subject: Re: [Boost-users] Switching from CreateThread to boost::thread
From: John Wilkinson (jwilkinson_at_[hidden])
Date: 2010-02-05 16:14:38


 
>> So this workerThread passes the socket off to another function that handles the command connection and then deletes/frees the data used.
>> All that aside, here's the issue. This while-loop generates hundreds of thousands of handles in a matter of days. This causes all kinds
>> of problems on the server (there's a similar issue with clients using identical functions) and either the server needs to be rebooted or
>> the program shut down. I tried to use WaitForSingleObject() and then CloseHandle() but it seems to close the handle prematurely. This
>> causes the client/server to not communicate and interrupt any data transfer. I am wondering if using boost::thread will make handling
>> the destruction of the threads easier. I've been researching it but I can't find any solid information on whether or not CloseHandle(),
>> or something similar, needs to be run. I'm just trying to see if using Boost is the right direction to go.

Yes, you need to call CloseHandle on those threads. References:

http://msdn.microsoft.com/en-us/library/ms682453%28VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/kdzttdcb%28VS.80%29.aspx

(Those were each the first result from googling the function name, by the way)

The thread data will hang around until (1) the thread function terminates, AND (2) all handles to it are closed. Note that calling CloseHandle does NOT in itself terminate the thread.

John
This e-mail message and any attachment(s) transmitted with it are intended only for the
use of the recipient(s) named above.This message may be privileged and/or confidential.
If you are not an intended recipient, you may not review, copy or distribute this message.
If you have received this communication in error, please notify us immediately by e-mail
and delete the original message.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net