🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2417

Re: Using TClientSocket in multi-threaded app

#2417
From: Mark Atkin
Date: Wed, 26 Apr 2006 17:34
69 lines
3183 bytes
"SF" <invalid@NOSPAMinvalid.com> wrote in message 
news:<444f4499$2@newsgroups.borland.com>...
> > TClientSocket *sock = new TClientSocket(MainForm);
>
> I always use
>
> TClientSocket *sock = new TClientSocket(NULL);
>

Me too, from now on ;)

> to create client sockets inside a thread. You yourself noticed this is the 
> right way.
>
> > My theory as to why I would get AVs is that maybe all three threads are 
> > calling new TClientSocket(MainForm) almost simultaneously and basically,
>
> I don't care about that. Why should MainForm be the owner of an object 
> created inside a different thread?
>

When I first coded this, I didn't realize that NULL was a valid argument.  I 
thought I had to supply a valid TComponent instance.  I now know that's not 
the case.

> > The biggest hole in my theory that I can see is that it doesn't really 
> > explain why it would work on my PC and not my clients.
>
> That should be deeply checked, but again, you shouldn't care too much IMO.
>

I've got the same opinion, now.  Who cares why it was working on my PC.  It 
probably shouldn't have been.  I guess I was lucky that it failed so quickly 
on my clients computer or this could have bitten me down the road.

> > It still could be a timing issue,
>
> Or another thousands of issues...
>
> > Also, the only advantage that I can see to having MainForm being the 
> > owner of the TClientSocket is that if something unexpected occurs and 
> > the TClientSocket doesn't get deleted somehow, the MainForm will free up 
> > the memory when the form gets destroyed.
>
> Not a big advantage. Almost a disadvantage under certain points of view.
>

I see that, now.

> > This advantage is greatly decreased by the fact that the form is never 
> > destroyed until the program exits, in which case Windows is going to 
> > free up the memory anyway.
>
> Anyway, your thread should be strong enough to handle any possible problem 
> and free the TClientSocket pointer by itself.
>
> Did you find anything more in the meantime?
>

Not really.  This definitely seems to have fixed my problem.  It wouldn't 
run more than 30 minutes before.  Now, it has run for days with no problems.

> HTH,
>
> Stefano.
>

Thanks Stefano.
Technical Details
Message-ID: <444faf34$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4447ee51$1@newsgroups.borland.com> <444f4499$2@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,f074aec44b23f651
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mark Atkin" <matkin@windrock.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4447ee51$1@newsgroups.borland.com> <444f4499$2@newsgroups.borland.com>
Subject: Re: Using TClientSocket in multi-threaded app
Date: Wed, 26 Apr 2006 13:34:44 -0400
Lines: 71
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 69.2.92.6
Message-ID: <444faf34$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1146072884 69.2.92.6 (26 Apr 2006 10:34:44 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail