Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Re: TIdTCPServer shutdown
| Subject: | Re: TIdTCPServer shutdown |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Fri, 14 Sep 2007 15:57:38 |
"Toby Piper" <news@CompCraft.com> wrote in message
news:46eb0941@newsgroups.borland.com...
> Oh, then I totally misunderstood what I read about Critical sections
A critical section only works when all threads that share a protected
resource enter and leave the critical section equally. If one thread (in
this case, the main thread) does not do that, then the critical section
becomes useless to the other threads, as the non-conforming thread is
bypassing the lock.
> I understood it to say that the critical section was run in the main
thread
Nope. Your understanding is not even close to how critical sections
actually work. I suggest you read Microsoft's documentation instead of some
third-party documentation.
> If I understand what you are saying then the critical section
> only applies to worker threads - yes?
A critical section can be used in any thread, including the main thread.
What it can't be used for is protecting access to the main thread's UI,
because the VCL does not use any critical sections internally when accessing
the UI components. So it doesn't matter how many critical sections you use
in worker threads to wrap your UI operations. The main thread will bypass
them all. That is why you need to delegate all UI access to run in the
context of the main thread only. That has nothing to do with critical
sections.
Gambit
none