100 % CPU usage with wxSocket

Kip Warner kip at thevertigo.com
Thu Dec 20 12:55:15 PST 2007


On Thu, 20 Dec 2007 16:33:01 +0100, Lukasz Michalski wrote:

> On Thursday 20 December 2007, Kip Warner wrote:
>> Greetings,
>>
>> When I am done with the socket in each client socket thread, I call
>> ClientSocket->Destroy() in the thread deconstructor. The thread exits
> 
> Your problem is caused by ScheduleForDestroy() call from child thread
> which modifies global list that is not thread safe.
> 
> I would rather call ClientSocket->Close() and delete pointer to socket
> in thread that owns it. If you don't use events then there is no need
> for Destroy(). Destroy() can be used safely only in main thread.
> 
> Regards,

Thank you very much Lukasz. I will try that. Are you sure it is ok to 
delete the socket object manually after calling close? The documentation 
always says not to manually invoke the deconstructor like that and to 
just use Destroy(). Also, your method isn't mentioned in the docs. Not 
saying it isn't valid, in fact, it's the only method that makes sense 
right now. I am just curious as to why something so critical as that 
isn't in there since I am sure I am not the only one to not use sockets 
through events and in a secondary thread?

Kip






More information about the wx-users mailing list