Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Jan : Re: AThreads and Thread manager..

www.cryer.info
Managed Newsgroup Archive

Re: AThreads and Thread manager..

Subject:Re: AThreads and Thread manager..
Posted by:"Turboz" (turb..@turboz.moved.in)
Date:Sat, 6 Jan 2007 00:25:20

Hi Remy,

Thanks for the previous reply, it was VERY helpful and I appreciated your
time to explain those issues to me so well!

Anyway, there was just one thing I'd also like to ask about with reference
to the CriticalSections..

>> Yes, all the threads go straight into a CriticalSection as soon as
> the
>> OnExecute event is fired. They then leave the CS when they are done
> with
>> their 'doings'.
>
> You are not using a single critical section across multiple clients,
> are you?  That is very inefficient.  Lock one client for writing data
> and all clients are locked.  Each client should have its own critical
> section, as I showed you earlier.

Well, to cut a long story short, yes I am using just one CS in the entire
server app for all TIdTCPServer threads.

As I understood it, a CriticalSection was designed to stop multiple threads
accessing shared memory at the same time - EG public declarations like
arrays, strings, booleans etc.

If I use one CriticalSection for each client (IE, one in each thread) then
how does that protect these shared items? - I didn't think it could be done
so I'm rather confused about it now. I noticed in the code you posted for
me, that you were creating a CS in each 'User' constructor and likewise
destroying the CS for each user destructor. Surely if each one has it's own
CS that defeats the point of the object because multiple clients can gain
access to and modify the same shared memory at the same time?

Sorry to be a pain, but your really great at helping and I really appreciate
it!

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive