Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Re: TIdTCPServer shutdown

www.cryer.info
Managed Newsgroup Archive

Re: TIdTCPServer shutdown

Subject:Re: TIdTCPServer shutdown
Posted by:"Toby Piper" (ne..@compcraft.com)
Date:Fri, 14 Sep 2007 14:47:49

> How are you writing to the Memo exactly?  Are you accessing it directly
> (you
> shouldn't be) or are you using a synchronization method to access it
> indirectly?

I had the Memo.Lines.Add method wrapped in a critical section - something
like:

critsec.enter;
try
  memo.lines.add( "shutdown' );
finally
  critsec.leave;

> Keep in mind that TIdTCPServer is multi-threaded.  The OnConnect,
> OnExecute,
> and OnDisconnect events are all triggered in the context of a worker
> thread,
> not in the context of the thread that owns the TIdTCPServer.  When you set
> the server's Active property to false, the setter method for that property
> has to wait for all of the inner threads to terminate before it can exit.
> If you do something that blocks that, such as performing a synced
> operation
> in one of the event handlers, and that operation waits on the thread that
> is
> already waiting on the server shutdown (such as when the server resides in
> the application's main thread), then you will block the event handler from
> exiting, thus blocking the worker thread from terminating, and thus
> blocking
> the server from finishing its shutdown.

Yes, I see what you are saying - it would result in a deadlock.

> If you are using TIdSync or TThread.Synchronize() to access the Memo, and
> you don't need to wait for the Memo to update itself before continuing,
> then
> try using asynchrous access, such as the TIdNotify class.  That way, no
> blockage can occur.

Thanks!! I'll try that.

Thanks for all your input!!

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive