Thanks all. Just the re-assurance I needed.
It is not deep recursion. It is only one or two levels max. And this code can be as slow as it likes, because it is hardly ever called, however it is critical. I think it is better to be safe, obvious and slow than fast and sorry :-) -----Original Message----- From: Dennis Chuah [mailto:[EMAIL PROTECTED] Sent: Friday, February 13 2004 7:19 a.m. To: NZ Borland Developers Group - Delphi List Subject: Re: [DUG] TCriticalSection Allan, The thread does not block on the second call to Acquire, but if the routine has a deep recursion level, Acquire/Release will be called many times, plus the try ... finally block will also be executed many times. This is rather inefficient - it is better to write a wrapper method that only locks the critical section once. Dennis. ----- Original Message ----- From: "Allan, Samuel" <[EMAIL PROTECTED]> To: "NZ Borland Developers Group - Delphi List" <[EMAIL PROTECTED]> Sent: Thursday, February 12, 2004 4:50 PM Subject: [DUG] TCriticalSection > Quick question, I think I'm right, but I just want confirmation: > > If a thread calls Aquire a second time on the same TCriticalSection, > then the thread does not block right? > > The thread does not release the TCriticalSection until all calls to > Aquire have been matched by a call to Release? > > I have a recursive method that needs to be locked away behind a > TCriticalSection. Like I can rewrite so there's no problem, but this is > easier. > > procedure RecursiveMethod; > begin > criticalSection.Aquire; > try > ... > RecursiveMethod; > ... > finally > critcalSection.Release; > end; > end; > > _______________________________________________ > Delphi mailing list > [EMAIL PROTECTED] > http://ns3.123.co.nz/mailman/listinfo/delphi > _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
