[fpc-devel] Re: TThread.WaitFor delay
henry.vermaak at gmail.com
Wed Jun 19 16:45:26 CEST 2013
On Wed, Jun 19, 2013 at 04:05:19PM +0200, Ludo Brands wrote:
> On 06/19/2013 12:10 PM, Henry Vermaak wrote:
> > On Thu, May 30, 2013 at 03:54:08PM +0100, Henry Vermaak wrote:
> >> Hi list
> >> When I call TThread.WaitFor, I almost always get a 100ms delay,
> >> presumably due to the CheckSynchronize(100) here:
> >> Is it feasible to add an extra check so that this doesn't happen when
> >> FOnTerminate isn't assigned and DoSynchronizeMethod is false?
> >> Also, it looks like spinning on FFinished like this can get you into
> >> trouble with cpu re-ordering, or am I missing something?
> > Anyone have thoughts on this?
> WaitForThreadTerminate(FHandle, 0) blocks the main thread and skipping
> the spin on FFinished would block all threads that call synchronize
> until the thread that is waited for finishes. You can only test
> assignment of FOnTerminate for the current thread and not for other
Ah, right. I thought the spin on FFinished was only needed to prevent
deadlock if the current thread has an OnTerminate event. Why worry
about other threads synchronising at that point?
> DoSynchronizeMethod doesn't exist anymore in 2.7.1.
Right, sorry, I'm not really familiar with the internals.
> I agree the current implementation is not very satisfactory when you
> don't use synchronize. You could be better off using
> WaitForThreadTerminate yourself instead of WaitFor.
This is what I ended up doing, was just wondering if there's a way to
remove this penalty somehow.
More information about the fpc-devel